Consider the following method signatures:
public fooMethod (Foo[] foos) { }
and
public fooMethod (Foo... foos) { }
Explanation: The former accepts an array of Foo objects as an argument - fooMethod(new Foo[]{..})-, while the latter accepts an arbitrary number of arguments of type Foo and represents them as an array of Foo: s inside the method - fooMethod(fooObject1, fooObject2, etc...).
Java throws a fit if both are defined, claiming 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 the only way to call this method. The second method actually takes an arbitrary number of arguments Foo, and takes an array of Foo objects.
So the question is, since the last method seems more flexible, are there any reasons for using the first example, or have I missed something vital?
source
share