When overloaded methods, the method for a variable number of parameter in two ways
- Array overloaded
- ... Overload
The two methods, in fact, is the same, for example:
. 1 public class MethodArgsTest { 2 // a variable number of parameter format: Data types ... parameter name . 3 public void Show (String ... strs) { . 4 // of parameters passed String ... strs the strs as an array, the array how to use it how to use. 5 // deformable reference method number of parameter must be not declared at the end of the show (int i, String ... strs ) may, Show (STRs String ..., I int) . 6 // deformable method of parameter reference number, a maximum of only declare a reference deformable 7 } 8 // array . 9 public void Show (String [] STR) { 10 . 11 } 12 is 13 is public static void main (String [] args) { 14 MethodArgsTest test = new MethodArgsTest(); 15 test.show("aa", "bb", "cc", "dd"); 16 } 17 }
Code above manner, write
show(String ... strs)
show (String [] str)
will prompt the following error: