Recently I encounter a weird problem with respect to Java generics. I simplified the problem with snippet below :
public static void main(String[] args) {
String s = "Hello";
System.out.println(blindlyReturnGetObject());
}
private static <T> T getObject() {
return (T) new Object();
}
private static <T> T blindlyReturnGetObject() {
return getObject();
}
In case of JDK 1.6.0_03 and earlier versions, we were getting infamous compilation error
type parameters of <T>T cannot be determined; no unique maximal instance exists for type variable T with upper bounds T,java.lang.Object
whereas this code works perfectly in JDK 1.6.0_26 and later versions.
Is there anyway to get rid of this issue for earlier version of jdk 1.6 since our build servers are still running in earlier version of jdk 1.6?
While googling related to this issue, I came across a bug raised in
sunrelated to thisgenerics type inferenceissue.https://bugs.java.com/bugdatabase/view_bug?bug_id=6302954
So this is found to be fixed in later versions of
jdk 1.6.0_20and hence it was working injdk 1.6.0_26Thought its worth sharing.