-
Bug
-
Resolution: Not an Issue
-
P2
-
5.0
-
generic
-
generic
The type of int.class is Class<Integer>.
This basically destroys the type safety purported by type tokens:
import java.util.*;
class Test {
public static void main(String[] args) {
Collection<Integer> c = new Vector<Integer>();
c = Collections.checkedCollection(c, int.class);
c.add(0);
}
}
This program fails:
Exception in thread "main" java.lang.ClassCastException: Attempt to insert class java.lang.Integer element into collection with element type int
at java.util.Collections$CheckedCollection.typeCheck(Collections.java:2206)
at java.util.Collections$CheckedCollection.add(Collections.java:2240)
at Test.main(Test.java:7)
###@###.### 10/20/04 06:31 GMT
This basically destroys the type safety purported by type tokens:
import java.util.*;
class Test {
public static void main(String[] args) {
Collection<Integer> c = new Vector<Integer>();
c = Collections.checkedCollection(c, int.class);
c.add(0);
}
}
This program fails:
Exception in thread "main" java.lang.ClassCastException: Attempt to insert class java.lang.Integer element into collection with element type int
at java.util.Collections$CheckedCollection.typeCheck(Collections.java:2206)
at java.util.Collections$CheckedCollection.add(Collections.java:2240)
at Test.main(Test.java:7)
###@###.### 10/20/04 06:31 GMT
- relates to
-
JDK-6176992 (reflect) Add support to java.lang.Class for wrapper type conversions
- Open
-
JDK-6456930 Class.cast does not work for primitive types
- Open