Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

The varargs feature was introduced in the JDK v1.5.0. Its utility lies in allowing a method to accept a variable number of arguments.

Wiki Markup
According to the Java SE 6 documentation \[[Sun 06|AA. Java References#Sun 06]\]  [varargs|http://java.sun.com/j2se/1.5.0/docs/guide/language/varargs.html]:

...

Overloading varargs methods can create confusion as shown in this noncompliant code example. The programmer's intent is to invoke the variable argument (varargs) doSomething() method, but instead its overloaded, more specific form takes precedence.

...

Exceptions

Wiki Markup
*EX1:* Sometimes, it is desirable to violate the "do not overload varargs methods" advice for performance reasons (avoiding the cost of creation of an array instance and its initialization on every invocation of a varargs method). \[[Bloch 08|AA. Java References#Bloch 08]\]

...

The idiom shown above avoids the pitfalls of incorrect method selection by using non-ambiguous method signatures and can consequently be discreetly used where required.

...