Community
Participate
Working Groups
This might be a duplicate of bug 84496, but I'm rather new to generics so I'm not sure. In the code snippet below, the indicated line generates the following error when compiled with sun's javac: cannot find symbol symbol : method addAll(java.util.List<capture of ?>) location: interface java.util.List<capture of ?> untypedList.addAll(untypedList2); But with eclipse's compiler (3.1M6), it is not flagged as an error. And when the code runs, it generates a ClassCastException. ---- import java.util.ArrayList; import java.util.List; public class Test_Lists { public static void main(String[] args) { List<String> stringList = new ArrayList<String>(); stringList.add("foo"); List<Integer> intList = new ArrayList<Integer>(); intList.add(1); List<?> untypedList = stringList; List<?> untypedList2 = intList; //correctly flagged as error: untypedList.add(new Object()); //ditto: untypedList.add(untypedList2.get(0)); //but this is not flagged at all by eclipse: untypedList.addAll(untypedList2); for(String s : stringList){ //next line generates runtime ClassCastException Logger.log("Test_Lists.main: s: " + s); } } }
Added GenericTypeTest#test584. This is indeed a dup.
*** This bug has been marked as a duplicate of 84495 ***
oops, wrong dup bug number
*** This bug has been marked as a duplicate of 84496 ***