I have a (for me) complex Java generics problem. I've asked a similar question in stackoverflow before but came to the conclusion that this example made things overly complex. So, here the simplified question.
I have two classes as follows
abstract public class Base {
abstract public Base doSomething(Base arg);
}
public class Variant extends Base {
@Override
public Variant doSomething(Variant arg) { // <-- error
// code
}
}
The error message is "The method doSomething(Variant) of type Variant must override or implement a supertype method."
The selected answer in the initial question is to use generified versions class Base<T extends Base<T>>
and class Variant<T extends Variant<T>> extends Base<T>
, which works. But then, if I want to create an instance of Variant, I need to supply a generics parameter, even though I don't "need" one.
Is there a more simple solution?