Consider the following method signatures:
public fooMethod (Foo[] foos) { /*...*/ }
and
public fooMethod (Foo... foos) { /*...*/ }
Explanation: The former takes an array of Foo-objects as an argument - fooMethod(new Foo[]{..})
- while the latter takes an arbitrary amount of arguments of type Foo, and presents them as an array of Foo:s within the method - fooMethod(fooObject1, fooObject2, etc...
).
Java throws a fit if both are defined, claiming that they are duplicate methods. I did some detective work, and found out that the first declaration really requires an explicit array of Foo objects, and that's the only way to call that method. The second way actually accepts both an arbitrary amount of Foo arguments AND also accepts an array of Foo objects.
So, the question is, since the latter method seems more flexible, are there any reasons to use the first example, or have I missed anything vital?