Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Comment: minor grammar fixes

The Java compiler type-checks the arguments to each variable-arity (varargs) method to ensure that the arguments are of the same type or object reference. However, the compile-time checking is ineffective when Object or generic parameter types are used [Bloch 2008]. (Note that it does not matter if there are The presence of initial parameters of specific types , is irrelevant; the compiler will still not be able remain unable to check Object or generic variable-arity parameter types. ) A requirement for providing Enable strong compile-time type checking of variable-arity methods is to be as specific as possible when declaring by using the most specific type possible for the type of the method parameter.

...

Also, note that autoboxing does not allow 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 does not use casts or autoboxing and 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.

...