We have a method in class that takes generic parameter
public class XYZ {
public <T extends Animal> someMethod(T animal){}
}
I want to override this method in the subclass with specific type, but don’t know how. How to fix this?
public class ABC extends XYZ{
@Override
public Cat someMethod(Cat animal){} // error
}
One possible solution would be to make your
XYZclass generic:And declare your
ABCclass to be specific to cats:Now you can write: