Versions Compared

Key

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

Wiki Markup
The Java compiler type-checks the arguments to a varargs method to ensure that they are of the same type or object reference. However, the compile-time checking is ineffective when two method signatures are used in particular - {{Object}} and the generic type {{T}} \[[Bloch 08|AA. Java References#Bloch 08]\]. Another requirement for providing strong compile-time type checking of variable argument methods is to be as specific as possible when declaring the type of the method parameter.

Noncompliant Code Example

...

Wiki Markup
Retrofitting old methods containing {{final}} array parameters with generically typed varargs is not always a good idea. This is because if some method did not accept an argument of a particular type, it may be possible to override the compile-time checking so that with the use of generic varargs, it now compiles cleanly. \[[Bloch 08|AA. Java References#Bloch 08]\]. 

Also, note that autoboxing does not allow strong compile time type checking of primitive types and their corresponding wrapper classes.

...

Unmindful use of the varargs feature breaks strong compile-time type checking, may create creates ambiguity and diminish diminishes code readability.

Rule

Severity

Likelihood

Remediation Cost

Priority

Level

DCL08- J

low

unlikely

medium

P2

L3

...