Community
Participate
Working Groups
I found a new problem in support for generic types. See this code: interface Jukebox { <M extends Music, A extends Artist<M>> A getArtist (M music); } class JukeboxImpl implements Jukebox { public <M extends Music,A extends Artist<M>> A getArtist (M music){return null;} void test () { Elvis king = getArtist(new Rock()); } } interface Music {} class Rock implements Music {} class Classic implements Music {} interface Artist<M extends Music> {} class Elvis implements Artist<Rock> {} class Mozart implements Artist<Classic> {} JDT compiler produces errors like: "The method getArtist(Rock) is ambiguous for the type JukeboxImpl". But JDK 1.5.0_04's javac compiles this code normally; not only the method invocation is okay (no ambiguity), but javac makes the assignments to 'king' and 'amadeus' without even a warning (even if I use -Xlint:unchecked or -Xlint:all). This behavior of javac doesn't sound very correct either, because the inferred type of getArtist()'s return value should be "Artist<Rock>", that is not yet assignment-compatible to Elvis, this should produce a compiler error (not just a type-safety warning, because the incompatibility is in the erased type). The bug in JDT is also related to inheritance. If you remove the interface Jukebox, this erro disappears. There is no difference if I use interfaces, abstract classes, or a simple base class with a concrete definition of the method getArtist(); bug always happens if the method overrides something.
Only after posting I found bug 100869, that is apparently the same problem. Sorry. But I hope this adds some additional info, in particular I'd like to confirm that Sun's javac compiler is also wrong so I can report to Sun... (very likely the JCK has a hole here, otherwise neither JDT nor javac could be certified as compliant)
fixed & released in 3.1.1 stream
Added MethodVerify test066
released in 3.2 HEAD stream
Verified for 3.2 M2 with build I20050920-0010.
Verified for 3.1.1 using M20050923-1430.