Community
Participate
Working Groups
Sample code: ---- import java.util.LinkedList; import java.util.List; public class SuperTest { private static class C1 { } public static void main(String[] args) { List<C1> l = new LinkedList<C1>(); addObject(l); for (C1 c : l) { System.out.println(c); } } private static void addObject(List< ? super C1> l) { l.add(new Object()); } } ---- Eclipse 3.1M4 compiles this code without complaint, but javac correctly gives the following error: SuperTest.java:22: cannot find symbol symbol : method add(java.lang.Object) location: interface java.util.List<capture of ? super SuperTest.C1> l.add(new Object()); ^ Executing the Eclipse-compiled class shows the problem at runtime: Exception in thread "main" java.lang.ClassCastException: java.lang.Object at SuperTest.main(SuperTest.java:14) Eclipse will report an error if the lower bound (super C1) is removed: Bound mismatch: The method add(?) of type List<?> is not applicable for the arguments (Object). The wildcard parameter ? has no lower bound, and may actually be more restrictive than argument Object
*** This bug has been marked as a duplicate of 83398 ***