나는 특정 클래스의 배열 형 얻기 위해 다음과 같은 트릭을 사용Java의 Class.getArrayType?
@SuppressWarnings("unchecked")
public static <T> Class<T[]> getArrayType(Class<T> componentType) {
String arrayClassName = "[L" + componentType.getName() + ";";
try {
return (Class<T[]>) Class.forName(arrayClassName);
} catch (ClassNotFoundException e) {
throw new UnexpectedException("Can't get the array type for " + componentType, e);
}
}
을하지만,이 얻을 수있는 더 우아한 방법은 무엇입니까?
배열의 길이가 될 수 0 – finnw
나는 아마이 어쨌든 작품과 내가 생각하지 않는 0과 청소기 보이는 것에 동의 @finnw 그것은 어떤 이상한 문제가 있습니다. 왜냐하면 배열에 대한 객체 할당이 여전히 존재하고 클래스 참조를 얻은 후에 할당이 즉시 해제되기 때문입니다. –