Bug 342796

Summary: Use of <? extends MyClass>
Product: [Eclipse Project] JDT Reporter: danielbackman38
Component: CoreAssignee: Srikanth Sankaran <srikanth_sankaran>
Status: VERIFIED INVALID QA Contact:
Severity: enhancement    
Priority: P3 CC: amj87.iitr, srikanth_sankaran
Version: 3.6.2   
Target Milestone: 3.7 M7   
Hardware: PC   
OS: Windows 7   
Whiteboard:

Description danielbackman38 CLA 2011-04-14 03:33:45 EDT
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
Comment 1 Walter Harley CLA 2011-04-14 04:21:19 EDT
Please include some sample code that you believe should compile but that does not.
Comment 2 Srikanth Sankaran CLA 2011-04-14 05:17:23 EDT
Please also check the behavior with javac against your code.
Comment 3 Srikanth Sankaran CLA 2011-04-20 02:37:42 EDT
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.
Comment 4 Ayushman Jain CLA 2011-04-25 06:05:20 EDT
Verified for 3.7M7.