Given the following two class definitions:
class C1<T extends C1<T>> {} class C2<U> extends C1<C2<U>> {}
And the following type declaration:
C1<C2<?>> a;
Intuitively, he feels that the declared type a must be valid, but thatβs not how the JDK-8u45 behaves. Instead, we get something like the following output:
Test.java:3: error: type argument C2<?> is not within bounds of type-variable T C1<C2<?>> a; ^ where T is a type-variable: T extends C1<T> declared in class C1 1 error
( Edit: I was dingus here, they answered this part: C2<?> Does not extend C1<C2<?>> . The problem associated with the declaration c below is still an open question.)
But C2<?> Extends C1<C2<?>> , which, it would seem, trivially satisfies the estimate. Viewing JLS gives no additional coverage, as far as I can see. It should be just as simple as satisfying the binding with a subtype relation, since C2<?> Is not a wildcard type, and therefore the capture transformation is just an identity conversion in the argument.
There are situations when it becomes a little less clear, for example, the following class definitions are accepted:
class C3<T extends C3<?>> {} class C4<Y, Z> extends C3<C4<Z, Y>> {} class C5<X extends C3<X>> { void accept(X x); }
All this is fine, but if we try the following declaration:
C5<C6<?, ?>> b;
Everything is getting weirder. C6<?, ?> Is a subtype of C3<C6<?, ?>> , so the declaration must be valid in accordance with my interpretation of the specification indicated above regarding the declaration C1<C2<?>> . The problem is that obviously not every subtype C6<?, ?> Really satisfies this estimate, so now, for example, C5.accept() resolves its parameter type C6<?, ?> And therefore can accept arguments that violate the restriction on X , i.e. Any where the parameterizations Y and Z not identical.
Where am I wrong here? How much do I not understand the subtype relationship?
( Edit: The next part of the question remains unanswered, but I translated it to a new question here , since a completely different problem is actually ... Sorry for the mess and not using the site very well haha ββ...)
In addition, I also have problems with capture conversion in similar situations. Take the following type of ad:
C1<? extends C2<?>> c;
Unlike a similar declaration of a at the beginning, this compiles into the JDK-8u45. If we look at the specification for capturing conversion , however, it looks like this declaration should lead to a compile-time error.
In particular, the upper bound for capturing a variable of type CAP#T is defined as glb(Bi, Ui[A1:=S1,...,An:=Sn]) , where in this case Bi allows the binding of the wildcard C2<?> And Ui[A1:=S1,...,An:=Sn] resolves to C1<CAP#T> .
From this, glb(C2<?>, C1<CAP#T>) allows the intersection type C2<?> & C1<CAP#T> , which is invalid because C2<?> And C1<CAP#T> are both class types, not interface types, but none of them is a subtype of the other.
This (obvious) violation of the rule becomes more understandable in determining the type of intersection itself .
I'm sure this is not a mistake, and I'm just making some simple mistakes somewhere ... but if no one here can shed any light on this, I will try the compiler-dev mailing list or something like that.
Thanks for any help!