Is (double[]).getClass().getName() defined?
I have a simple class that holds an ArrayList of a single type of Objects.
Most of the time it will be a double[] but other times it might be a data
holding class.
I want to be able to query the holding class for what type of objects are
in the ArrayList. I was going to return a Class object.
public Class getObjectType(){
return some Class;
}
I get "[D" as the Class name for double[]. Can i rely on that name or
should i just wrap the double[] array into a wrapper class?
I wrote this test class:
publicclass ArrayClassTest{
publicstaticvoid main(String[] args){
new ArrayClassTest();
}
public ArrayClassTest(){
System.out.println("This Class: " + this.getClass().getName());
double[] dblArray ={0.0, 1.0, 2.0};
int[] intArray ={1, 2, 3};
Object[] objArray ={null};
ArrayClassTest[] actArray ={this};
System.out.println("Array Class: " + dblArray.getClass().getName());
System.out.println("Array Class: " + intArray.getClass().getName());
System.out.println("Array Class: " + objArray.getClass().getName());
System.out.println("Array Class: " + actArray.getClass().getName());
}
}
Which yields these results:
This Class: ArrayClassTest
Array Class: [D
Array Class: [I
Array Class: [Ljava.lang.Object;
Array Class: [LArrayClassTest;

