Getting the array Class<?> of a given class

2019-05-26 04:43发布

问题:

Given a Class<?> that describes class A, is it somehow possible to get the Class<?> that matches the class A[]?

Class<?> clazz = A.class;
Class<?> arrayclazz = clazz.toArray(); // ??

assert arrayclazz.equals(A[].class);

回答1:

java.lang.reflect.Array.newInstance(clazz, 0).getClass()



回答2:

use A[].class. I hope this help.