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?

1

2 Answers 2

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

See javadoc of Class.getName() for details.

Sign up to request clarification or add additional context in comments.

1 Comment

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)
1

According to this page use:

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.