Reputation: 79
int[] a = new int[]{1,2,3};
int[] b = {1,2,3};
What difference between a and b? Am I right that first is object and 'a' is a link, and second is a primitive type and 'b' is a variable? But what advantages/disadvantages have first array?
Upvotes: 1
Views: 146
Reputation: 1074335
In an initialization like you have there, there is no difference between them at all. They result in the same bytecode. Note that you have to use the first form in an assignment, though:
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?
No, in both cases, you have a variable (a
, b
) which is a reference to the array.
Upvotes: 5