메서드에서 중첩 된 제네릭을 사용할 때 경고가 표시되지 않습니다. 왜 그런가요? 중첩 된 제네릭에 검사되지 않은 경고가 표시되는 이유는 무엇입니까?
public static <T> T[] genericTest(T[] aa) {
return aa;
}
그래서 내가 왜이 첫 번째 코드 블록의 경고가 아닌 초를 얻고있다 : 나는 방법을 수정하는 경우
package test;
public class subc {
public static void main(String[] args) {
Integer aa[] = new Integer[10];
infunction(aa);
// Not Warning , Use genericTest !!!!!!!!!!!
Integer[] abc = genericTest(aa, aa.getClass());
@SuppressWarnings("unused")
Integer a = abc[0];
}
public static <T> T[] genericTest(T[] aa, Class<? extends T[]> class1) {
return aa;
}
public static <T> T[] infunction(T[] aa) {
// Warning, Use genericTest(unchecked) !!!!!!!!!!
T[] result = (T[]) genericTest(aa, aa.getClass());
return result;
}
}
는 경고가 없다?
왜 클래스 T []>'를 확장합니까? 'Class extends T>'또는'class'('genericTest' 메쏘드에서)이라고 말할 수 있습니다. –
그냥 테스트 코드, 그리고 내가 복사, Arrays.copyOf –
public static T [] copyOf (U [] original, int newLength, Class extends T []> newType) { T [] copy = (Object) newType == (Object) Object []. class) ? (T []) new Object [newLength] : (T []) Array.newInstance (newType.getComponentType(), newLength); System.arraycopy (원본, 0, 복사본, 0, Math.min (original.length, newLength)); 반품 사본; } 단순한 경우 만 바꿉니다. –