I have the following model to make controllers in my application. Obviously, the full model is more complex but I will focus on the only part that is causing me problems:
public abstract AbstractController<T> {
abstract protected Class<T> getType();
}
public ParentController extends AbstractController<Parent> {
@Override
protected Class<Parent> getType() {
return Parent.class;
}
}
Now I would like to extend the Parent object and have a controller for the son, it would look like this:
public SonController extends ParentController {
@Override
protected Class<Son> getType() {
return Son.class;
}
}
The problem is that the method getType() shows incompatibility in compilation (expects the class Parent).
I tried to play around with the generics but I can't find a solution. The method getType is used in several methods from the abstract controller and I would really like to avoid overriding those.
Any ideas would be wellcome.