I am following up on this question, 1268817
In the question, we find a way to create an isntance of an object given a the name (as a string) of the class.
But what about to create an array of those objects... how would one initialize that.
I was thinking something in the line of but doesnt seem to work
Object[] xyz = Class.forName(className).newInstance()[];
Try:
Here is an example creating an array of String:
For an array of 10 elements.
Annoyingly it returns an object, instead of an object array.
As Tom points out, this is to allow:
An int[] is not assignable to an Object[], so the return type has to be an Object. But it is still annoying as you very rarely want to do this.
Use Array:
and catch the appropriate exceptions.