In Java, when is the {a,b,c,...} array shorthand inappropriate, and why?

It's only acceptable during a declaration. You can, however, use new double[] {0, 1, 2}.

JLS §10.6:

An array initializer may be specified in a declaration, or as part of an array creation expression.

An array creation expression is the new double[] { } syntax.


You can use braces notation only at the point of declaration, where compiler can infer the type of array from the declaration type.

To use it anywhere else you need to use Array Creation Expression:

return new double[] {0,1,2};