6

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?

Community
  • 1
  • 1
yegor256
  • 102,010
  • 123
  • 446
  • 597
  • There is an other thread for this [here][1] too! [1]: http://stackoverflow.com/questions/1087177/what-do-those-strange-class-names-in-a-java-heap-dump-mean – kisp Jul 10 '12 at 08:15

2 Answers2

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

See javadoc of Class.getName() for details.

axtavt
  • 239,438
  • 41
  • 511
  • 482
  • int[].class is probably better in general, but this is useful for example when using an alternative JVM language that gives access to Class but doesn't allow the PRIMITIVE[] syntax (such as e.g. Xtend) – vorburger Jan 09 '17 at 22:24
1

According to this page use:

Class intArray = Class.forName("[I");
Jan Zyka
  • 17,460
  • 16
  • 70
  • 118