-
Bug
-
Resolution: Duplicate
-
P4
-
5.0
-
x86
-
windows_xp
FULL PRODUCT VERSION :
java version "1.5.0"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.5.0-b64)
Java HotSpot(TM) Client VM (build 1.5.0-b64, mixed mode)
java version "1.5.0_01"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.5.0_01-b08)
Java HotSpot(TM) Client VM (build 1.5.0_01-b08, mixed mode, sharing)
ADDITIONAL OS VERSION INFORMATION :
Microsoft Windows XP [Version 5.1.2600]
(Japanese)
A DESCRIPTION OF THE PROBLEM :
The following Test.java is warned but it should not be warned.
STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
>javac -J-Duser.language=en -version -Xlint:unchecked Test.java
javac 1.5.0_01
Test.java:8: warning: [unchecked] unchecked cast
found : java.util.List<capture of ? extends java.lang.String>
required: StringList
java.util.List<String> b = (StringList) a; // warned but safe.
^
1 warning
EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
Test.java can be compiled without warnings.
ACTUAL -
A [unchecked] warning.
(See "Steps to Reproduce")
REPRODUCIBILITY :
This bug can be reproduced always.
---------- BEGIN SOURCE ----------
--------Test.java--------
class StringList extends java.util.LinkedList<String> {
}
public class Test {
public static void main(String[] args) {
java.util.List<? extends String> a = new StringList();
java.util.List<String> b = (StringList) a; // warned but safe.
}
}
---------- END SOURCE ----------
CUSTOMER SUBMITTED WORKAROUND :
Use StringList.class.cast(a)
###@###.### 2004-12-22 18:38:01 GMT
java version "1.5.0"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.5.0-b64)
Java HotSpot(TM) Client VM (build 1.5.0-b64, mixed mode)
java version "1.5.0_01"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.5.0_01-b08)
Java HotSpot(TM) Client VM (build 1.5.0_01-b08, mixed mode, sharing)
ADDITIONAL OS VERSION INFORMATION :
Microsoft Windows XP [Version 5.1.2600]
(Japanese)
A DESCRIPTION OF THE PROBLEM :
The following Test.java is warned but it should not be warned.
STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
>javac -J-Duser.language=en -version -Xlint:unchecked Test.java
javac 1.5.0_01
Test.java:8: warning: [unchecked] unchecked cast
found : java.util.List<capture of ? extends java.lang.String>
required: StringList
java.util.List<String> b = (StringList) a; // warned but safe.
^
1 warning
EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
Test.java can be compiled without warnings.
ACTUAL -
A [unchecked] warning.
(See "Steps to Reproduce")
REPRODUCIBILITY :
This bug can be reproduced always.
---------- BEGIN SOURCE ----------
--------Test.java--------
class StringList extends java.util.LinkedList<String> {
}
public class Test {
public static void main(String[] args) {
java.util.List<? extends String> a = new StringList();
java.util.List<String> b = (StringList) a; // warned but safe.
}
}
---------- END SOURCE ----------
CUSTOMER SUBMITTED WORKAROUND :
Use StringList.class.cast(a)
###@###.### 2004-12-22 18:38:01 GMT
- duplicates
-
JDK-4916620 legal cast is rejected
- Closed