Bug 164665 - [1.5][compiler] Generics supertype doesn't compile with sun - incompatible types
Summary: [1.5][compiler] Generics supertype doesn't compile with sun - incompatible types
Status: VERIFIED INVALID
Alias: None
Product: JDT
Classification: Eclipse Project
Component: Core (show other bugs)
Version: 3.2   Edit
Hardware: PC Windows XP
: P3 normal with 1 vote (vote)
Target Milestone: 3.4 M5   Edit
Assignee: Philipe Mulet CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2006-11-15 11:50 EST by Kenny MacDermid CLA
Modified: 2008-02-04 11:32 EST (History)
1 user (show)

See Also:


Attachments
Code that compiles in eclipse, but not sun (1.98 KB, application/x-zip-compressed)
2006-11-15 11:59 EST, Kenny MacDermid CLA
no flags Details

Note You need to log in before you can comment on or make changes to this bug.
Description Kenny MacDermid CLA 2006-11-15 11:50:40 EST
Hello,

When using a generic factory method like:

public static <T, U extends T> TypedCollection<T> createTypedCollection(Class<U> c)

to do something along the lines of:

TypedCollection<SuperType> = createTypedCollection(SubType.class)

if will compile fine with Eclipse and is completely workable, but will not compile with javac (1.5.0_09). I plan to test this with the nightly build of eclipse once it is done downloading.

I have not yet managed to find a spec with who is correct in this case.

I have test classes that show this working in eclipse, but returning the error message:
incompatible types
found   : TypedCollection<SubType>
required: TypedCollection<SuperType>
Comment 1 Olivier Thomann CLA 2006-11-15 11:52:38 EST
Please attach a complete test case for investigation.
Comment 2 Kenny MacDermid CLA 2006-11-15 11:59:44 EST
Created attachment 53917 [details]
Code that compiles in eclipse, but not sun

Code is in the default package. javac *.java does not compile, but it does in eclipse.
Comment 3 Philipe Mulet CLA 2008-01-23 07:09:29 EST
I believe our behavior is correct; and that it would indicate a bug in javac. Basically acording to JLS 15.12.2.8, the invocation of
    <T, U extends T> TypedCollection<T> createTypedCollection(Class<U> c)

should yield {U == SubTypeClass} and {T == SuperTypeAbstractClass}.
U being inferred during argument inference 15.12.2.7, and T being inferred from 15.12.2.8 from expected type (invocation occurs on right hand side of variable declaration).

Marking the bug as invalid, since our behavior is correct already.
Added GenericTypeTest#test1242
Comment 4 Philipe Mulet CLA 2008-01-23 07:13:29 EST
btw, I just checked javac 1.7 (1.7.0-ea), and he seems they now agree with us as well.
Comment 5 Jerome Lanneluc CLA 2008-02-04 11:32:42 EST
Verified for 3.4M5