How to create a Class of primitive array?

丶灬走出姿态 提交于 2019-12-06 02:59:47

问题


This question is derived from: How to get this Method object via reflection?

I'm trying to do the following:

Class c1 = Class.forName("[Ljava.lang.Integer;"); // works fine
Class c1 = Class.forName("[Lint;"); // doesn't work, since it's primitive

What is the workaround? int[].class is the only solution?


回答1:


Class c1 = Class.forName("[I");

See javadoc of Class.getName() for details.




回答2:


According to this page use:

Class intArray = Class.forName("[I");


来源:https://stackoverflow.com/questions/5076690/how-to-create-a-class-of-primitive-array

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