我最近一直在思考定义数组的两种方式之间的区别:
int[]数组 int[]数组
有区别吗?
我最近一直在思考定义数组的两种方式之间的区别:
int[]数组 int[]数组
有区别吗?
当前回答
它们是一样的。其中一种(对某些人来说)比另一种更具可读性。
其他回答
最可取的选项是int[] a——因为int[]是类型,而a是名称。 (第二个选项与此相同,只是空格放错了位置)
它们在功能上没有区别。
没有区别,但是Sun建议把它放在这里解释的类型旁边
Java语言规范说:
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, as in this
example:
byte[] rowvector, colvector, matrix[];
This declaration is equivalent to:
byte rowvector[], colvector[], matrix[][];
因此,它们将产生完全相同的字节代码。
它们完全相等。Int[]数组是首选样式。int array[]只是作为等效的c兼容样式提供。
它们是一样的。其中一种(对某些人来说)比另一种更具可读性。