Getting the array Class<?> of a given class

眉间皱痕 提交于 2020-01-02 18:23:08

问题


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.



来源:https://stackoverflow.com/questions/5091348/getting-the-array-class-of-a-given-class

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!