I have a method as given below that gives me compile time error.
class Parent {
public abstract <T extends Parent> T copy();
}
and in Child class
class Child extends parent{
public <T extends Parent> T copy() {
return new Child();
}
}
By generics I am telling type eraser that I would return child object still it is not letting me do this. Anyone have an opinion/solution on this?
I can solve my problem with new approach as given below.
class Parent {
public Parent copy(){
//some stuff
}
}
class Child extends Parent{
@Override
public Child copy(){
Child c = (Child) super.copy();//I want to avoid this type casting here.
}
}
So the above way solves my problem but I have to TYPE CAST in the child if I want to use parent class copy method and additionaly want to do more stuff in Child class.
So considering both, do u have better way of solving problem?