...
sum()
--> returns zero.sum(42)
--> returns 0+42 = 42.sum(10, 20)
--> returns 0+10+20 = 30.sum(100, 1000, 10000)
--> returns 11100 etc
Varargs and Visitors
Vararg input parameters are very useful when you might want to call a method, such as the accept
method of a host (and hence a case on the visitor), with varying numbers of input parameters, or perhaps, none at all.
...
If you need an input parameter, just set the P
(the generic type of the input parameter) to the type you need and call the accept
method with as many values as you need. Note that the one restriction of a vararg input parameter is that all the input values have to be of the same type.
...