This post originated from an RSS feed registered with Java Buzz
by dion.
Original Post: Playing with varargs
Feed Title: techno.blog(Dion)
Feed URL: http://feeds.feedburner.com/dion
Feed Description: blogging about life the universe and everything tech
Tom McQueeney has been playing with varargs.
It will definitely be interesting to see how often people use varargs in their designs... especially code APIs. As with everything, hopefully they won't be overused.
When you see examples such as:
public Person(String... params) {
lastName = firstName = middleName = nickName = "";
if (params.length > 0) lastName = params[0];
if (params.length > 1) firstName = params[1];
if (params.length > 2) middleName = params[2];
if (params.length > 3) nickName = params[3];
if (params.length > 4) {
throw new IllegalArgumentException(
"Constructor called with too many arguments"
);
}
}
it gets a little scary. How often will someone pass in "Almaer", "Dion" instead of "Dion", "Almaer". Tom points out this issue himself
Named parameters please :) :)