Bug 336142 - [1.5][compiler] Invalid Type Mismatch error
Summary: [1.5][compiler] Invalid Type Mismatch error
Status: VERIFIED INVALID
Alias: None
Product: JDT
Classification: Eclipse Project
Component: Core (show other bugs)
Version: 3.7   Edit
Hardware: PC Windows XP
: P3 normal (vote)
Target Milestone: 3.7 M6   Edit
Assignee: Srikanth Sankaran CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2011-02-02 15:11 EST by Corey CLA
Modified: 2011-03-07 10:28 EST (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 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