The elipses (...) is used to indicate
varargs, a new feature of
Java 1.5.
All it REALLY means is that the variable
args is an array. So it could have just as easily have been defined as:
Basically, the difference in notation is just to help the readability of the code. When you see the parameter declared as an array, it typically implies that there is some sort of logical similarity of all the items in the array, whereas when you see it defined with the elipses, each of the elements typically represents some completely different parameter of the method.
There is, a syntactic difference with the
actual parameters passed as well. With the introduction of varargs, instead of passing an array as the last argument, you can pass a comma separated list of objects instead.
i.e.
Personally, I think that varargs are terrible. They introduce a lot of ambiguity to method signatures, making it more difficult to predict which overloaded version of a method will be called (this is specified by the jls, but it is still confusing). Generally, if you're going to use varargs,
you should avoid overloading the method. Also, varargs prevents type safety, moving java further away from being a strongly typed language, which I think is a bad thing. For instance, if instead of int, you used Object, then a user could technically send you an array of any size of any type of object they wish to send. So you really don't know what you're going to get. I fail to see how this is a good thing, and I strongly encourage everybody to avoid varargs in most cases. The code required to make a varargs method safe, and do the logic required to deal with the fact that the arguments are variable is often more complicated and confusing then if you simply write a couple of overloaded methods to handle the different expected sets of parameters.
One good stylistic use of var args might be in statistics, when you want to create functions to evaluate properties of a small sample set.
e.g.
Hope this helps!
- Adam