int[] a = new int[]{1,2,3};
int[] b = {1,2,3};
a和b有什么区别?我说得对吗,第一个是对象,“a”是一个链接,第二个是原始类型,“b”是一个变量?但是 first array 有什么优点/缺点呢?
最佳答案
在像您那样的初始化中,它们之间根本没有区别。它们产生相同的字节码。请注意,您必须在作业中使用第一种形式,不过:
int[] b;
b = {1,2,3}; // <== Syntax error
Am I right that first is object and 'a' is a link, and second is a primitive type and 'b' is a variable?
不,在这两种情况下,您都有一个变量 (a
, b
),它是对数组的引用。
关于java - 数组声明之间的区别,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9556340/