我看到有人在Java初始化和数组这样Java数组初始化后声明
int[] s;
s = new int[]{ and put the list here..}
与
int[] s = { the list here}
这些是做这件事的两个可接受的方式?
我看到有人在Java初始化和数组这样Java数组初始化后声明
int[] s;
s = new int[]{ and put the list here..}
与
int[] s = { the list here}
这些是做这件事的两个可接受的方式?
是的,两者都是创建java整数数组的同样有效的方法。第二个版本只是 第一个版本的快捷方式语法。
更多的是,这里:http://download.oracle.com/javase/tutorial/java/nutsandbolts/arrays.html
是的,后者是用于在特定情况下,前者的简写:后者只能在一个变量的初始化直接使用(其中类型被给予直接在左边),而前者通常可用作表达。
是的,两种情况下生成的实际字节码完全相同。
+1用于提及使用快捷语法的**限制**。 – informatik01