> Hi all,
>
[quoted text clipped - 10 lines]
> TIA,
> Daniel
I think this may work:
Class.forName("[L"+className+";");
For more dimensions, add leading "[" symbols. This calls forName on
the string that the array's class object's getName() returns.
Patricia
Piotr Kobzda - 28 Jun 2008 11:59 GMT
> I think this may work:
>
> Class.forName("[L"+className+";");
>
> For more dimensions, add leading "[" symbols. This calls forName on
> the string that the array's class object's getName() returns.
And here is a bit extended use of your advice:
public class ArrayUtil {
public static Class<?> arrayType(Class<?> componentType, int dims)
throws ClassNotFoundException {
char[] da = new char[dims];
java.util.Arrays.fill(da, '[');
return Class.forName(
new String(da) + nativeTypeDescriptor(componentType),
false, componentType.getClassLoader());
}
private static String nativeTypeDescriptor(Class<?> type) {
String name = type.getName();
char c = name.charAt(0);
if (c == '[') {
return name;
}
if (type.isPrimitive()) {
if (c == 'l') { // long
return "J";
} else if (c == 'b' && name.length() == 7) { // boolean
return "Z";
} else {
return String.valueOf(Character.toUpperCase(c));
}
}
return "L" + name + ";";
}
}
piotr
Daniel Hohenberger - 30 Jun 2008 07:58 GMT
Thanks a lot.

Signature
my homepage : http://hd42.de
'Life is wasted on the living' - Zaphod Beeblebrox the Fourth