mh taqia mh taqia - 1 year ago 78
Android Question

Create static array using Class.forName

In Android there is a undeclared (hidden) class named "" and I want to create static array of it. Any thing like this:

Class<?> clazz = Class.forName(""); // Ok.
Class<?> clazz_array = Class.forName("[]"); // Method threw 'java.lang.ClassNotFoundException' exception.

To build this hypothetical code:

FontFamily[] families = {fontFamily};

How can I do it?


Answer Source

You should be able to create an array reflectively then get its class. Example:

Class<?> clazzArray = Array.newInstance(clazz, 0);
Object families = Array.newInstance(clazz, 1); 
Array.set(families, 0, fontFamily);
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download