The following code compiles both test methods using javac in JDK7 but JDK8 will only compile willCompile method.
The error for willNotcompile is:
"The method method(Class<T>) in the type Klasa is not applicable for the arguments (Class)."
@Test
public void willCompile() throws InstantiationException, IllegalAccessException {
Class klass = getObject(Class.class);
method(klass);
}
@Test
public void willNotCompile() throws InstantiationException, IllegalAccessException {
method(getObject(Class.class));
}
<T> ResponseEntity<T> method (Class<T> klasa) {
return new ResponseEntity<T>(HttpStatus.OK);
}
public static <T> T getObject(Class<T> clazz) throws IllegalAccessException, InstantiationException {
return clazz.newInstance();
}