Class.getArrayType en Java?
Utilizo el siguiente truco para obtener el tipo de matriz de una clase específica:
@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);
}
}
Pero, ¿hay alguna forma más elegante de conseguir esto?