vendredi 28 septembre 2018

Reflexion and Inheritance in java

I'd like to have something like this:

Class<Parent<K>> oppositeType;
if(input instanceof Child2){
  oppositeType = Child1.class;
} else if(input instanceof Child1){
  oppositeType = Child2.class;
}
// Here is some logic that I don't want to duplicate

But it looks like I cannot. Looks like I cannot even though Child1 and Child2 inherit from Parent. Any idea on how to do something like this?





Aucun commentaire:

Enregistrer un commentaire