|
答案出自
Java 5.0泛型编程之泛型类型2005-10-18 09:18 作者: cat 出处: Matrix 责任编辑:方舟
// Here's a basic parameterized list.
List<Integer> li = new ArrayList<Integer>();
// Wrap it for runtime type safety
List<Integer> cli = Collections.checkedList(li, Integer.class);
// Now widen the checked list to the raw type
List lll = cli;
// This line compiles but fails at runtime with a ClassCastException.
// The exception occurs exactly where the bug is, rather than far awayl.add("hello");
lll.add("hello"); |
|