Versions Compared

Key

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

...

Retrofitting old methods containing final array parameters with generically typed variable arity parameters is not always a good idea. For example, given a method that does not accept an argument of a particular type, it could be possible to override the compile-time checking — through checking—through the use of generic variable arity parameters — so parameters—so that the method would compile cleanly rather than correctly, causing a run-time runtime error [Bloch 2008].

Also, note that autoboxing prevents strong compile-time type checking of primitive types and their corresponding wrapper classes.

...

Variable arity signatures using Object and imprecise generic types are acceptable when the body of the method lacks both casts and autoboxing , and also compiles without error. Consider the following example, which operates correctly for all object types and type-checks successfully.:

Code Block
bgColor#ccccff
Collection<T> assembleCollection(T... args) {
  Collection<T> result = new HashSet<T>();
  // addAdd each argument to the result collection
  return result;
}

...