Is there any difference between “Object[] x” and “Object x[]”?

前端 未结 5 1932
时光说笑
时光说笑 2020-12-03 22:17

I was updating a legacy code base in Java and I found a line like this:

Object arg[] = { new Integer(20), new Integer(22) };

That line catc

5条回答
  •  自闭症患者
    2020-12-03 22:57

    Both are legal and both work. But placing [] before the array's name is recommended.

    From Javadocs:

    You can also place the square brackets after the array's name:

    float anArrayOfFloats[]; // this form is discouraged
    

    However, convention discourages this form; the brackets identify the array type and should appear with the type designation.

提交回复
热议问题