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
?