CERT

Versions Compared

Key

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

...

According to the Java SE 6 documentation [Sun 2006]:

As an API designer, you should use [varargs methods] sparingly, only when the benefit is truly compelling. Generally speaking, you should not overload a varargs method, or it will be difficult for programmers to figure out which overloading gets called.

...

DCL08-EX1: It may be desirable to violate this guideline for performance reasons. One such reason would be to avoid the cost of creating an array instance and initializing it on every invocation of a method [Bloch 2008].

Code Block
bgColor#ccccff
public void foo() { }
public void foo(int a1) { }
public void foo(int a1, int a2, int... rest) { }

...

Automated detection is straightforward.

Bibliography

[Bloch 2008]

Item 42: "Use Varargs Judiciously"

[Steinberg 2005]

"Using the Varargs Language Feature"

[Sun 2006]

varargs

...

DCL53DCL64-JGJ. Beware of integer literals beginning with 0      01. Declarations and Initialization (DCL)      VOID DCL09-J. Enable compile-time type checking of varargs typesImage Added