I have a problem with generics in Java in combination with interface inheritance.
Here is an exampe:
public interface Type0 { }
public interface Type1 extends Type0 {
void method();
}
public interface SomeInterface0<T extends Type0> {
T get();
}
public interface SomeInterface1<T extends Type1> extends SomeInterface0<T> { }
Now, when I try to use field of type SomeInterface1 without type parameter java comiler treats type of SomeInterface1.get() method result as Type0. And can’t compile something like this:
...
SomeInterface1 si1;
...
si1.get().method();
So, why SomeInterface1<T extends Type1> has a default vlue for T = Type0 ?
When leaving out generic parameters, almost all of the generics logic is skipped. Determining the type of T will not be ‘smart’ and just look at the way T is defined within that class/interface.
If you want to use the generics logic, you should provide generic parameters instead of leaving them out – they can still be very, well, ‘generic’: