Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Variable parameter class?

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?

like image 636
Ajay Avatar asked Jun 04 '26 20:06

Ajay


2 Answers

An Object[] array.

To get the runtime type information:

a.getClass().isArray() -> true
a.getClass().getComponentType().getName() -> java.lang.Object
like image 159
Thomas Jung Avatar answered Jun 07 '26 11:06

Thomas Jung


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
like image 40
dfa Avatar answered Jun 07 '26 10:06

dfa