Reputation: 2398
I have I problem.
In a method I receive a general Object as parameter and I have to retrieve the name of the class
public void myMethod(Object o)
String className = o.getClass().getName();
...
}
It works, except when i give to the methods arrays.
For example if a pass to the method an array of double (double[]
), getClass().getName()
returns me [D
How can I retrieve something like double[]
?
Upvotes: 8
Views: 12382
Reputation: 2039
Simple name of the class is what you are looking for:
System.out.print(new String[0].getClass().getSimpleName());
and the result well be:
String[]
Upvotes: 6
Reputation: 19682
[D
means an array of doubles. Check this link for an explanation on class names. Why would you like something like double[]
instead?
Upvotes: 14
Reputation: 7729
If you give using the wrapper class, you get '[Ljava.lang.Double'
Double[] d = new Double[10]
d.getClass().getName() gives you [Ljava.lang.Double
Upvotes: 1