在 java 中创建对象数组的正确方法是什么?
What is the correct way to create a object array in java?
我见过这样的例子:
Type arrayname[] = new Type[];
也可以写成:
Type[] arrayname = new Type[]
我对这样的表达方式很困惑!
我应该把 []
放在哪里?
允许以上任何一种。都产生相同的字节码。 JLS-10.2 Array Variables 说(部分)
The []
may appear as part of the type at the beginning of the declaration, or as part of the declarator for a particular variable, or both.
我见过这样的例子:
Type arrayname[] = new Type[];
也可以写成:
Type[] arrayname = new Type[]
我对这样的表达方式很困惑!
我应该把 []
放在哪里?
允许以上任何一种。都产生相同的字节码。 JLS-10.2 Array Variables 说(部分)
The
[]
may appear as part of the type at the beginning of the declaration, or as part of the declarator for a particular variable, or both.