Archive

Archive for May, 2009

Java 5 Generics, Sun JDK and Eclipse JDT differences

May 17th, 2009 mohan 2 comments

Another one of those annoying differences between Eclipse JDT and Java (SUN) JDK, especially using generics. Sometime, you have to live outside the IDE to compile the code (e.g. CI), have you ever got bitten by this:

Compilation Failure ... type parameters cannot be determined; no unique maximal instance exists for type variable <T> with upper bounds T,java.lang.Object

Solution

I don’t know whether it is fixed in the latest JDK (JDK5 u16, still has this bug), but essentially the Sun JDK compiler is not able to infer the type correctly. The solution involves helping the compiler by providing the type parameter explicitly. An example:

someObject.genericMethod() to someObject.&lt;T&gt;genericMethod()<br />
Categories: Java Tags: