Community
Participate
Working Groups
I20040914-gtk (may be a dup of bug 74119, but not sure) A super-bound type variable produces wrong errors, I believe: public void write(List<? super Number> list) { list.add(new Integer(3)); // XXX should work list.add(new Double(3.4)); // XXX should work Number num= new Double(3.4); list.add(num); // works list.add(new Object()); // XXX should fail } This code produces a ClassCastException: void fail() { List<Number> numbers= new ArrayList<Number>(); test.write(numbers); for(Number n: numbers) { // CCE when an Object comes back n.toString(); } }
Looks like the subtype relationship check between the wildcard lower bound and the argument's type should just go the other way 'round.
With following test case: import java.util.List; public class Test { public void write(List<? super Exception> list) { list.add(new RuntimeException()); // JDT fails, Javac works list.add(new IllegalMonitorStateException()); // JDT fails, Javac works Exception exc = new Exception(); list.add(exc); // both works list.add(new Object()); // JDT works, Javac fails list.add(new Throwable()); // JDT works, Javac fails list.add(new Exception()); // both works } } javac reports following errors: Test.java:11: cannot find symbol symbol : method add(java.lang.Object) location: interface java.util.List<capture of ? super java.lang.Exception> list.add(new Object()); // JDT works, Javac fails ^ Test.java:12: cannot find symbol symbol : method add(java.lang.Throwable) location: interface java.util.List<capture of ? super java.lang.Exception> list.add(new Throwable()); // JDT works, Javac fails ^ 2 errors
We now accept all scenarii with recent tuning in wildcard compatibilities. Added regression test: GenericTypeTest#test410 *** This bug has been marked as a duplicate of 74119 ***