samedi 30 mai 2015

How to know the class type without using instanceOf or getClass()?

I have a class Person which is inherited by Student and Employee. I have another class PersonList, it has a list of type Person i.e List (elements can be of both Student and Employee type)

There is a 3rd party API which has two overloaded methods i.e

void display(Employee emp) and void display (Student student)

When I iterate over Person list, I need to know the object type so that I can call to the appropriate display() method.

I dont want to use instanceOf or getClass().





Aucun commentaire:

Enregistrer un commentaire