I have class structure like this:
class A1,A2,..,An extends A;
class B1,B2,..,Bn extends B;
And class that converts Ai
into Bi
:
private B1 convert(A1 a1){}
...
private Bn convert(An an){}
How can I define single public method with signature like <? extends B> convert(<? extends A> a)
?
Now I have only this approach:
B convert(A a){
if(A.getClass().equals(A1.class)){
return convert((A1)a);
}...
}
Can I use instanceof if perfomance is important and the method will be called frequently?