Bug 336142

Summary: [1.5][compiler] Invalid Type Mismatch error
Product: [Eclipse Project] JDT Reporter: Corey <corey>
Component: CoreAssignee: Srikanth Sankaran <srikanth_sankaran>
Status: VERIFIED INVALID QA Contact:
Severity: normal    
Priority: P3 CC: amj87.iitr, Olivier_Thomann
Version: 3.7   
Target Milestone: 3.7 M6   
Hardware: PC   
OS: Windows XP   
Whiteboard:

Description Corey CLA 2011-02-02 15:11:11 EST
Build Identifier: 20100917-0705

Eclipse is marking as error the following:
Collection<Comparable<?>> b = new HashSet<Comparable<Number>>();
The error is: Type mismatch: cannot convert from HashSet<Comparable<Number>> to Collection<Comparable<?>>.

Interestingly, the following has no error:
Comparable<?> a = new Comparable<Number>() {
   public int compareTo(Number o) { return 0; }
};

Please also note that both the above snippets compile fine in 1.6.0_22.

Reproducible: Always
Comment 1 Olivier Thomann CLA 2011-02-02 15:19:43 EST
Srikanth, please investigate.
Comment 2 Corey CLA 2011-02-02 15:30:52 EST
I'm sorry, but I was incorrect in that it compiled in 1.6.0_22.  This leads me to believe that it is user error, not an Eclipse bug.
Comment 3 Srikanth Sankaran CLA 2011-02-16 04:16:30 EST
As you have discovered, this is the intended behavior.
You may want to get hold of a good tutorial: http://java.sun.com/j2se/1.5/pdf/generics-tutorial.pdf
is a good one.

"In general, if Foo is a subtype (subclass or subinterface) of Bar,
and G is some generic type declaration, it is not the case that G<Foo>
is a subtype of G<Bar>."

Resolving as INVALID.
Comment 4 Ayushman Jain CLA 2011-03-07 10:28:58 EST
Verified for 3.7M6