0

How can I load an array using loadClass method?

String className = "Customer[]";
Thread.currentThread().getContextClassLoader().loadClass(className);
3
  • 2
    Maybe Creating New Arrays or Java Reflection - Arrays Commented Jan 11, 2016 at 23:59
  • Punter Vicky, are you trying to load an array using the loadClass method or load the array's class. If it's the latter, is there any reason you wouldn't use the Class.forName() method? Commented Jan 12, 2016 at 3:55
  • Thanks MadProgrammer and Jonathan. I am trying to load an array with specific type. Commented Jan 12, 2016 at 4:11

1 Answer 1

1

You don't. You do not load the array class, just the class of the underlying type. The JVM will synthesize the array class when required.

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

2 Comments

Thanks EJP. Does it mean I can't use this method to load an array and should use java reflection to create a new array in order to dynamically create one?
You should use new Customer[...] if you can, otherwise java.lang.reflect.Arrays.

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.