"array initializer" is only available for declarations / assignments:
Object[] o = { 1, 2 };
Or for "array creation expression" :
new Object[] { 1, 2 };
Not for method calls:
It is as it is ... You can read about it in JLS, chapter 10.6. Array initializers . Exposure:
An array initializer can be specified in a declaration ( ยง8.3 , ยง9.3 , ยง14.4 ) or as part of an array creation expression ( ยง15.10 ) to create an array and provide some initial values.
Besides the fact that it is not defined in JLS right now, there seems to be no reason why a future version of Java will not allow the use of array literals / arrays in other contexts. An array type can be inferred from the context in which the array literal is used, or from the variable initializers contained in it
Of course, you can declare func1 argument to varargs. But then you have to be careful with overloading, as this can cause some confusion on the site of the call site
source share