| Start |
|---|
Specifying a varargs parameter The three periods after the final parameter's type indicate that the final argument may be passed as an array or as a sequence of arguments. Varargs can be used only in the final argument position. |
| Working with Varargs parameters Using varargs as a parameter for a method definition, it is possible to pass either an array or a sequence of arguments. If a sequence of arguments are passed, they are converted into an array automatically. This example shows both an array and a sequence of arguments being passed into the Output: If you define the method like this, it will give compile-time errors. RemarksA “varargs” method argument allows callers of that method to specify multiple arguments of the designated type, each as a separate argument. It is specified in the method declaration by three ASCII periods ( The method itself receives those arguments as a single array, whose element type is the type of the varargs argument. The array is created automatically (though callers are still permitted to pass an explicit array instead of passing multiple values as separate method arguments). Rules for varargs:
You must follow above rules otherwise program will give compile error. |
Read Article
https://develop.horje.com/learn/1434/reference