String array initialization as constructor parameter [duplicate]
String[] s = {"FOO", "BAR"};
this is allowed at declaration time only
You can't
String[] s;s={"FOO", "BAR"};
Because Type[] x = { ... }
is an initialization syntax for arrays. The { ... }
is interpreted in a specific way only in that specific context.
For you want a simple way to pass a String array, I suggest you use varargs
class Test { public Test(String...args);}// same as new Test(new String[] { "test", "one" })Test t = new Test("test", "one");