I am using a fluent interface with inheritance. I declared the base class Constructor protected so you cant create a Foo<Bar> which would result in a ClassCastException on calling add(). But i am having trouble with the static method that returns a new Foo instance.
public class Foo<T extends Foo<T>> // if i change to extends Foo i only get warnings { public static Foo<Foo> createFoo() // <-- error { return new Foo<Foo>(); // <-- error } protected Foo() {} public T add() { //... return (T)this; } } public class Bar extends Foo<Bar> { public Bar sub() { //... return this; } } This is mostly an excercise(personal not homework) in Fluent Interfaces, Domain-specific language and Generics, so please dont ask what i need it for.
Edit: Eclipse error
Bound mismatch: The type Foo is not a valid substitute for the bounded parameter <T extends Foo<T>> of the type Foo<T>