Bug 342796 - Use of <? extends MyClass>
Summary: Use of <? extends MyClass>
Status: VERIFIED INVALID
Alias: None
Product: JDT
Classification: Eclipse Project
Component: Core (show other bugs)
Version: 3.6.2   Edit
Hardware: PC Windows 7
: P3 enhancement (vote)
Target Milestone: 3.7 M7   Edit
Assignee: Srikanth Sankaran CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2011-04-14 03:33 EDT by danielbackman38 CLA
Modified: 2011-04-25 06:05 EDT (History)
2 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
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.