ITEM 53: USE VARARGS JUDICIOUSLY
245
Item 53: Use varargs judiciously
Varargs methods, formally known as
variable arity
methods [JLS, 8.4.1], accept
zero or more arguments of a specified type. The varargs facility works by first
creating an array whose size is the number of arguments passed at the call site,
then putting the argument values into the array, and finally passing the array to the
method.
For example, here is a varargs method that takes a sequence of
int
arguments
and returns their sum. As you would expect, the value of
sum(1,
2,
3)
is
6
, and
the value of
sum()
is
0
:
Do'stlaringiz bilan baham: