Community
Participate
Working Groups
I20050118 The following class compiles, but should not (javac complains): package test1; import java.util.List; public class SuperAssignment { void method(List<? super Number> list) { list.add(new Object()); // should fail list.add(new Integer(3)); // correct } }
Philippe, I encounter the same problem when implementing assigment compatibility accross contexts. I fixed it by distingusish between isAssignmentCompatible and isTypeArgumentCompatible because both need different rules: List<? extens Number>= List<Integer> but ? extends Number != Integer List<? super Number>= List<Object> but ? super Number != Object
Another case: public class A<T extends Number> { List<? super T> lhs; List<? extends Number> rhs; { lhs.add(rhs.get(0)); } } Javac rejects this
Another case: public class A<U extends Number> { List<? super Number> lhs; List<? super U> rhs; { lhs.add(rhs.get(0)); } }
public class A<U extends Number> { List<? super Integer> lhs; List<? extends Number> rhs; { lhs.add(rhs.get(0)); } }
import java.util.List; public class A<U extends Number> { List<? super Number> lhs; List<? super Integer> rhs; { lhs.add(rhs.get(0)); } }
Added GenericTypeTest#test475-481. Problem comes from wrong wildcard SUPER bound check implementation. Indeed the parameterized type compared ok. Fixed, thanks for all test cases (all exposing the same one issue)
*** Bug 84091 has been marked as a duplicate of this bug. ***
Verified in I20050214