We are currently in the process of migrating an application from Java 7 to Java 8. After fixing a some compilation issues, I stumbled upon an issue similar to the following ques
A better alternative would be:
public class Test {
public static void main(String[] args) {
System.out.println(String.valueOf(getVal("xxx"))); // 7: prints the result, 8: Exception
}
@SuppressWarnings("unchecked")
public static T getVal(T param) {
// do some computation based on param...
return param; // actual return type only depends on param so the caller knows what to expect
}
}
which will work in both Java 7 and Java 8.