Java SE5 Adds a mutable parameter list attribute parameters can be defined like this, (Object...args). Variable parameters are defined with "...", and args is an array of mutable parameters. As an example:
Package sample; Class a{} public class Newvarargs { static void PrintArray (Object...args) {for (Object Obj:args) System.out.print (obj+ ""); System.out.println (); } public static void Main (string[] args) { printArray (new Integer), New Float (3.14), New Double (11.11)); PrintArray (PrintArray ("One", "one", "one", " three"); PrintArray (New A (), new A (), new A ()); PrintArray ((object[]) new integer[]{1,2,3,4}); PrintArray (); }}
The output is:
3.14 11.113.14 11.11One and three[email protected] [email protected] [email protected]1 2 3 4
When a mutable parameter is specified, the compiler uses these arguments to populate a parameter array for a given variadic argument. This is why args can traverse with foreach. But if the parameter passed in itself is an array, the compiler will accept the array as a mutable parameter list, instead of wrapping the outer layer as a new array.
Java mutable parameter list