Aşağıdaki kod JDK7'de javac kullanarak her iki test yöntemini derler ancak JDK8 yalnızca willCompile
yöntemini derler.Java 7'den Java 8'e geçiş - derleme hatası
willNotcompile
için hatadır: "Klasa
bağımsız değişken (Class
) için geçerli değildir türü yöntem method
(Class<T>
)."
@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();
}
'willCompile()' rawtype kullanıyor, bu yalnızca eski kod için destekleniyor – Ferrybig
[Ham tür nedir ve neden kullanmamalıyız?] (Http://stackoverflow.com/questions/2770321/ ne-is-a-tür-ve-neden-değil-biz-use-it) – Tunaki
[iç içe geçmiş çağırma ve ham türleri hedefleme] (http://stackoverflow.com/a/26285613/2711488) – Holger