I want to define the following Java class:
public class DummyTemplate<S, D extends DummyTemplate<S,D>> {
S value;
D next;
public DummyTemplate(S value, D next) {
super();
this.value = value;
this.next = next;
}
public static DummyTemplate<String, DummyTemplate> factory(){
return new DummyTemplate<String, DummyTemplate>("wohoo", null);
}
}
created so i can subclass:
public class DummyTemplateSubclass<S, D extends DummyTemplateSubclass<S,D>> extends DummyTemplate<S, D>
(and the factoty of subclass returns DummyTemplateSubclass).
But the definition creates compile error:
Bound mismatch: The type DummyTemplate is not a valid substitute for the bounded parameter <D extends DummyTemplate<S,D>> of the type DummyTemplate<S,D>
Probably because the DummyTemplate must have parameters, how to define it then? i get the error
it compiles howewer only :
public static<D extends DummyTemplate<String,D>> D factory()
but then i got trouble on subclass:
public static<D extends DummyTemplateSubclass<String,D>> D factory(){
Name clash: The method factory() of type DummyTemplateSubclass has the same erasure as factory() of type DummyTemplate but does not hide it