Fluent API with multiple generic parameters and inheritance

43 views Asked by At

I am trying to implement a fluent API that contains specialized derived classes and I am using the Derived extends Base<Derived> method to obtain this parameter as Derived from base methods, but it doesn't seem to work with multiple generic parameters, for instance:

public class Specialized<T> extends Base<Specialized<T>, Iterable<T>> {
    void someAMethod() {
    }
}

public class Base<ThisType extends Base<ThisType, T>, T> {
    public ThisType baseMethod() {
        return getMe();
    }

    @SuppressWarnings("unchecked")
    public ThisType getMe() {
        return (ThisType) this;
    }
}

And later use it like:

new Specialized().baseMethod()
                 .someAMethod();

But baseMethod() doesn't return a Specialized object, so I am getting this error:

Cannot resolve method 'someAMethod()'

0

There are 0 answers