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 T
parameter types are used [Bloch 2008]. (Note that it does not matter if there are initial parameters of specific types, the compiler will still not be able to check Object
or generic T
variable arity parameter types.) A requirement for providing strong compile-time type checking of variable argument arity methods is to be as specific as possible when declaring the type of the method parameter.
...