Community
Participate
Working Groups
When i try to use <? extends MyClass> in a List I get a compilation error for inserting subclasses to MyClass. If i switch to <? super MyClass> the compilation error disappears. It seams to be that the compiler thinks backwards :) -- Configuration Details -- Product: Eclipse 1.3.2.20110218-0812 (org.eclipse.epp.package.jee.product) Installed Features: org.eclipse.jdt 3.6.2.r362_v20101117-0800-7z8XFW6FLFlmjJcvz03jyeFBLS_F
Please include some sample code that you believe should compile but that does not.
Please also check the behavior with javac against your code.
I presume your test case looks something like: import java.util.List; public class X { public static void foo(List<? extends X> p, List <? super X> q) { p.add(new X()); // ERROR q.add(new X()); // OK } } and p.add generates an error while q.add doesn't. This is the intended behavior. To see why consider p to be assigned a actual parameter that is a List<Y> where Y extends X. Allowing addition to X's to such a list would break type safety. Please reopen with a full test case if this is not the issue.
Verified for 3.7M7.