-
Bug
-
Resolution: Duplicate
-
P3
-
None
when compiling this code:
import java.util.*;
public class Test {
private static <T> void arrayMethod(List<? super T>[] args) {
listMethod(Arrays.asList(args));
}
private static <T> void listMethod(List<List<? super T>> list) {
}
}
javac issues error:
Test.java:5: error: method listMethod in class Test cannot be applied to given types;
listMethod(Arrays.asList(args));
^
required: List<List<? super T#1>>
found: List<List<? super T#2>>
reason: inference variable T#3 has incompatible bounds
equality constraints: List<? super CAP#1>
lower bounds: List<? super T#2>
where T#1,T#2,T#3 are type-variables:
T#1 extends Object declared in method <T#1>listMethod(List<List<? super T#1>>)
T#2 extends Object declared in method <T#2>arrayMethod(List<? super T#2>[])
T#3 extends Object declared in method <T#3>asList(T#3...)
where CAP#1 is a fresh type-variable:
CAP#1 extends Object super: T#2 from capture of ? super T#2
1 error
there seems to be a type capture out of place and probably not blessed by the spec
Reported by Attila Kelemen, see discussion at: https://mail.openjdk.org/pipermail/compiler-dev/2023-August/024034.html
import java.util.*;
public class Test {
private static <T> void arrayMethod(List<? super T>[] args) {
listMethod(Arrays.asList(args));
}
private static <T> void listMethod(List<List<? super T>> list) {
}
}
javac issues error:
Test.java:5: error: method listMethod in class Test cannot be applied to given types;
listMethod(Arrays.asList(args));
^
required: List<List<? super T#1>>
found: List<List<? super T#2>>
reason: inference variable T#3 has incompatible bounds
equality constraints: List<? super CAP#1>
lower bounds: List<? super T#2>
where T#1,T#2,T#3 are type-variables:
T#1 extends Object declared in method <T#1>listMethod(List<List<? super T#1>>)
T#2 extends Object declared in method <T#2>arrayMethod(List<? super T#2>[])
T#3 extends Object declared in method <T#3>asList(T#3...)
where CAP#1 is a fresh type-variable:
CAP#1 extends Object super: T#2 from capture of ? super T#2
1 error
there seems to be a type capture out of place and probably not blessed by the spec
Reported by Attila Kelemen, see discussion at: https://mail.openjdk.org/pipermail/compiler-dev/2023-August/024034.html
- duplicates
-
JDK-8206142 type inference: javac is incorrectly applying capture conversion during incorporation
- In Progress
- links to
-
Review openjdk/jdk/15463