I’ve just encountered an interesting problem related to Java generics. I’d like to use a concrete definition (DerivedPaginator) instead of “generified” definition (Paginator<Derived>). In order to do that, I have to change the method defined in the PaginatorTest. I’ve tried different combinations, but I still don’t know how to do it.
Could you please help me with solving this puzzle?
interface Base {
}
interface Derived extends Base {
}
interface Paginator<T extends Base> {
}
interface DerivedPaginator extends Paginator<Derived> {
}
interface PaginatorTest<T extends Base> {
// how to define this method so that it would accept DerivedPaginator?
void check(Paginator<T> it);
// nice try, but no cigar
//<Y extends Paginator<T>> void check(Y it);
}
interface DerivedPaginatorTest extends PaginatorTest<Derived> {
// this works fine
//@Override
//void check(Paginator<Derived> it);
// but this doesn't
@Override
void check(DerivedPaginator it);
}
You may declare
and use it like