Hi!
There is a given object of type java.lang.Class and I want to get the
array class corresponding to my class, aka the Class object with a
componentType identical to the given Class object.
I did it this way...
public static Class getArrayClass(Class componentType) {
return Array.newInstance(componentType, 0).getClass();
}
but creating an array just to get its class is &§&%/()/%$/&%$!!! in my
eyes...
Do you know a better solution?
Regards
Oliver
Chris Uppal - 30 Nov 2006 14:10 GMT
> There is a given object of type java.lang.Class and I want to get the
> array class corresponding to my class, aka the Class object with a
> componentType identical to the given Class object.
This is something of a FAQ (not to mention something of a stupid omission from
java.lang.Class). One discussion of the issue which I remember ('cos I took
part in it -- and because it went memorably and entertainingly wrong after a
while ;-) is here:
http://groups.google.co.uk/group/comp.lang.java.programmer/browse_frm/thread/5b9
8910e683da220
-- chris