views:

95

answers:

3

The following code

    public static void main(String[] args) {
        fun(new Integer(1));
    }
    static void fun(Object ... a) {
        System.out.println(a.getClass());
    }

gives the output :-

class [Ljava.lang.Object;

What class is this?

+7  A: 

An Object[] array.

To get the runtime type information:

a.getClass().isArray() -> true
a.getClass().getComponentType().getName() -> java.lang.Object
Thomas Jung
+6  A: 

according to the JVM specifications it is simply an array of java.lang.Object:

  • [ means a monodimensional array
  • LfullyQualifiedName; means a class, L; is just syntax
dfa
L is just syntax? without any sense?.. weird..
Ajay
it is used only as delimiter, no special meaning; did you read the specifications?
dfa
+1  A: 

This is how varargs (methods with a variable number of arguments) work in Java - the varargs argument will look like an array inside the method.

Jesper