Der folgende Code kompiliert beide Testmethoden mit javac in JDK7, aber JDK8 kompiliert nur die Methode willCompile
.Migration von Java 7 nach Java 8 - Kompilierungsfehler
die Fehler für willNotcompile
sind: "Die Methode method
(Class<T>
) in der Art Klasa
nicht anwendbar für die Argumente ist (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();
}
Die 'willCompile()' verwendet Rawtypes, dies wird nur für alten Code unterstützt – Ferrybig
[Was ist ein Rohtyp und warum sollten wir ihn nicht verwenden?] (Http://stackoverflow.com/questions/2770321/ what-is-a-row-type-und-why-shallnt-we-use-it) – Tunaki
[Zieleingabe in verschachtelten Aufruf- und Rohtypen] (http://stackoverflow.com/a/26285613/2711488) – Holger