Array constants can only be used in initializers

From JavaErrors

Jump to: navigation, search

You can get the error

  Array constants can only be used in initializers

if you use the {...} array form in anything but an initializer.

WRONG

 private int[] foo() {
   int[] x = new Array[3];
   x = {1,2,3};
   return  x;
 }

RIGHT

 private int[] foo() {
   int[] x = {1,2,3};
   return  x;
 }