I have a method having an array parameter like:
public static void foo(int[] param) {
// Some code
}
And also I can call the method by writing like
foo(new int[3]);
Normally, we declare and initialize an array by new operator or double braces initializer like {1, 2, 3}. For example, int[] foo = new int[3];
or int[] foo = {1, 2, 3};
.
But it's impossible to use double brace initializer as a parameter for a method. {}
is only available for creating an array object.
And here is my question: Are there any differences between new operator and {}
?
If there is, what is it?