Each Java array has a component type. When used in the initializer, the compiler indicates that the type of the new array (right side) is the same as the type of declaration (left side).
When there is no declaration, the compiler does not know what the type of the component of the array should be. You must be explicit using the expression setObject(new Object[] { new Object() })
One may ask why the compiler does not deduce the type from the declared type of the method parameter, as it happens when the variable is initialized. But the compiler allows a call method based on parameter types; if you donβt know the method you are calling, you cannot deduce any of its parameter types. There is no rounding when initializing a variable.
source share