Possible Duplicate:
Class.getArrayType in Java?
I need to get the class for a type that is represented by a string. I am trying to invoke getMethod and I only have a list of strings for the types it requires.
Class.forName(str) works when str is a simple class, but not, for example, with an array like so:
Class<?>[] typeClasses = new Class<?>[]{Class.forName("my.type.class[]")};
Method method = someClass.getMethod(methodString, typeClasses);
One way to get hold of the
Classobject for an array type is to callgetClass()on an array instance that you created reflectively; e.g.You can also use
Class.forName()but you need to specify the class name in internal form; e.g. the class name for anObject[]is"[Ljava.lang.Object;". See Class.getName() for details of the class name format.