I have a function which first check the type of the passed argument:
public void myFunc(Object myObj){
if(myObj instanceof Student){
Student p = (Student) myObj;
}else{
Teacher p = (Teacher) myObj;
}
//after above check I want to handle p in a generic way
//of course the following p is not resolved...
p.getName();
p.registerSelf();
}
p
always needs to cast first. How to make the compiler first know p's type then invoke the common function both Teacher
& Student
have .
My Person and Teacher are generated automatically by using apache avro. I am not able to define the two classes(Person & Student) to extends the same class.