Prz*_*wak 1 java arrays declaration multidimensional-array
可能重复:
Java中数组初始值设定项内包含尾随逗号的数组
为什么以下语句在java中是正确的:
int[][] a = { {1,2,}, {3,4}};
Run Code Online (Sandbox Code Playgroud)
是否应该因为不必要的逗号而导致编译错误?
Trailing comma in a array initialization like that are ignored by compiler. Those are generally added so that later on adding something to the array, just requires adding the element without worrying about comma.
It is wierd, but is allowed.
This is also listed in JLS - Section#10.6 (Array Initializers): -
An array initializer is written as a comma-separated list of expressions, enclosed by braces { and }.
尾随逗号可能出现在数组初始值设定项中的最后一个表达式之后,将被忽略.
| 归档时间: |
|
| 查看次数: |
253 次 |
| 最近记录: |