http://docs.oracle.com/javase/specs/jls/se7/html/jls-4.html#jls-4.9
For each Ti (1 ≤ i ≤ n), let Ci be the most specific class or array type, so that Ti <: Ci. Then there must be some Tk <: Ck such that Ck <: Ci for any I (1 ≤ i ≤ n), or a compile-time error occurs.
For 1 ≤ j ≤ n, if Tj is a variable of type, then let Tj 'be an interface whose members coincide with the public members of Tj; otherwise, if Tj is an interface, then let Tj '- Tj.
Then the intersection type has the same elements as the class type (§8), with an empty body, the direct superclass Ck and the direct superinterfaces T1 ', ..., Tn' declared in the same package in which the intersection type appears.
I expected the following code to throw a compile-time error, but that is not the case:
public interface I1 {}
public interface J1 extends I1 {}
public interface J2 {}
public interface J3 extends J2 {}
class C implements J1, J3 {}
public class A<T extends J1 & J3> {
public static void main(String[] args) {
A<C> a = new A<>();
}
}
As far as I understand, the types Ti <: Ci look like this:
Now I will need to have Tk <: Ck, where Ck <: C1 and Ck <: C2, but if Ck: = C1, then I1 <: J2 is false, and if Ck: = C2, then J2 <: I1 is false.
What am I missing here?
source
share