T
Tom Anderson
If i have a class, is there some way i can make a class for the
corresponding array? To clarify, i'm after an implementation for:
void makeArrayClass( Class cl )
Such that
makeArrayClass( cl ).getComponentType().equals( cl )
So that i can do, for example:
import java.lang.reflect.Array ;
void example( Class cl )
{
Class arrayCl = makeArrayClass( cl ) ;
Object[][] array = (Object[][])Array.newInstance( arrayCl, 3 ) ;
array[0] = Array.newInstance( cl, 3 ) ;
array[0][0] = cl.newInstance()
}
My end goal is to make arrays of arbitrary dimension and size (and they
may be ragged, so i can't use Array.newInstance(Class,int[])).
I've poked about in Class and Array, but can't see anything.
TIA and hello to all,
tom
corresponding array? To clarify, i'm after an implementation for:
void makeArrayClass( Class cl )
Such that
makeArrayClass( cl ).getComponentType().equals( cl )
So that i can do, for example:
import java.lang.reflect.Array ;
void example( Class cl )
{
Class arrayCl = makeArrayClass( cl ) ;
Object[][] array = (Object[][])Array.newInstance( arrayCl, 3 ) ;
array[0] = Array.newInstance( cl, 3 ) ;
array[0][0] = cl.newInstance()
}
My end goal is to make arrays of arbitrary dimension and size (and they
may be ragged, so i can't use Array.newInstance(Class,int[])).
I've poked about in Class and Array, but can't see anything.
TIA and hello to all,
tom