-
Bug
-
Resolution: Unresolved
-
P4
-
8, 9
Let's consider following code:
public class Test13 {
interface Iface<A1, A2 extends A1> {
String m(A1 t);
}
static void m(Iface<? super Number, ? super Integer> i) {
}
public static void run() {
m((Number a) -> a.toString());
}
}
It compiles successfully.
While according to 18.5.3:
1. Just one constraint Number=A1 is created causing only A1 to be instantiated in jls-18.5.3-210.
2. A2 is left unchanged as "? super Integer" as it's specified by jls-18.5.3-220-B. So jls-18.5.3-220 finally should yield Iface<Number, ? super Integer>.
3. According to jls-18.5.3-230 since second type argument contains wildcard, non-wildcard parameterization should be the resulted parameterization.
4. But the non-wildcard parameterization should fail according to jls-9.9-200-C.1-B because second type argument is a wildcard and corresponding type parameter is bound by type parameter (A2 extends A1).
5. So finally the compilation should fail while actually it succeeds.
It looks like resolution takes place along with reduction in jls-18.5.3-210 in javac.
public class Test13 {
interface Iface<A1, A2 extends A1> {
String m(A1 t);
}
static void m(Iface<? super Number, ? super Integer> i) {
}
public static void run() {
m((Number a) -> a.toString());
}
}
It compiles successfully.
While according to 18.5.3:
1. Just one constraint Number=A1 is created causing only A1 to be instantiated in jls-18.5.3-210.
2. A2 is left unchanged as "? super Integer" as it's specified by jls-18.5.3-220-B. So jls-18.5.3-220 finally should yield Iface<Number, ? super Integer>.
3. According to jls-18.5.3-230 since second type argument contains wildcard, non-wildcard parameterization should be the resulted parameterization.
4. But the non-wildcard parameterization should fail according to jls-9.9-200-C.1-B because second type argument is a wildcard and corresponding type parameter is bound by type parameter (A2 extends A1).
5. So finally the compilation should fail while actually it succeeds.
It looks like resolution takes place along with reduction in jls-18.5.3-210 in javac.
- duplicates
-
JDK-8163092 Non-wildcard parameterization exists for a wildcard and a type parameter bound
- Closed
- is blocked by
-
JDK-8145614 9.9: Fix non-wildcard parameterization process to match javac
- Open
-
JDK-8048543 JLS8 18.5.3: inference variable seems to be instantiated unexpectedly
- Closed