-
Bug
-
Resolution: Duplicate
-
P4
-
8
-
generic
-
generic
FULL PRODUCT VERSION :
A DESCRIPTION OF THE PROBLEM :
The following program does not compile using javac (but does compile using the eclipse compiler).
public static void main(String... s) {
List<?> l = Arrays.asList(1, 2, 3, 4);
if (l.get(0) instanceof Integer) {
System.out.println((int) l.get(0));
}
}
incompatible types: capture#1 of ? cannot be converted to int
REPRODUCIBILITY :
This bug can be reproduced always.
---------- BEGIN SOURCE ----------
public static void main(String... s) {
List<?> l = Arrays.asList(1, 2, 3, 4);
if (l.get(0) instanceof Integer) {
System.out.println((int) l.get(0));
}
}
-> incompatible types: capture#1 of ? cannot be converted to int
---------- END SOURCE ----------
CUSTOMER SUBMITTED WORKAROUND :
public static void main(String... s) {
List<?> l = Arrays.asList(1, 2, 3, 4);
if (l.get(0) instanceof Integer) {
System.out.println((Integer) l.get(0));
}
}
-> OK ! Just changing from primitive to object
A DESCRIPTION OF THE PROBLEM :
The following program does not compile using javac (but does compile using the eclipse compiler).
public static void main(String... s) {
List<?> l = Arrays.asList(1, 2, 3, 4);
if (l.get(0) instanceof Integer) {
System.out.println((int) l.get(0));
}
}
incompatible types: capture#1 of ? cannot be converted to int
REPRODUCIBILITY :
This bug can be reproduced always.
---------- BEGIN SOURCE ----------
public static void main(String... s) {
List<?> l = Arrays.asList(1, 2, 3, 4);
if (l.get(0) instanceof Integer) {
System.out.println((int) l.get(0));
}
}
-> incompatible types: capture#1 of ? cannot be converted to int
---------- END SOURCE ----------
CUSTOMER SUBMITTED WORKAROUND :
public static void main(String... s) {
List<?> l = Arrays.asList(1, 2, 3, 4);
if (l.get(0) instanceof Integer) {
System.out.println((Integer) l.get(0));
}
}
-> OK ! Just changing from primitive to object
- duplicates
-
JDK-8144832 cast conversion fails when converting a type-variable to primitive type
- Closed
- relates to
-
JDK-8166396 5.5: Clean up description of legal conversions in casts
- Closed