Consider this case:
class A {}
class B<T extends A, E extends T> {
B<?, A> b;
B<?, ? extends A> b2;
}
As I understand type bounds, in this case effective upper bounds of both T and E is class A. So the question: why javac doesn't accept class A as argument in declaration of field b, but accepts wildcard ? extends A in declaration of field b2?
With the following classes:
Think of it like this:
E extends T extends AWith
B<?,A>thenT -> ?andE -> AA extends ? extends AWhere the
?could be any subclass ofA, let's sayC.A extends C extends Ais clearly invalid.So that's why it's a compile error.
Note for Eclipse users:
Eclipse 4.9.0 compiler disagreed with javac 8u and Intellij and did not emit a compile error for the generic arguments in
B<?,A>. I assume this is a bug in the Eclipse compiler but I have not consulted the JLS to confirm this.This assumed bug has been reported here.