Java allows methods to use variable parameters after 1.5, the advantage of a mutable parameter is that it allows 0 or more parameters to be passed. For example, there is a code to download the following:
Java code 650) this.width=650; "class=" star "src=" Http://yizhenn.iteye.com/images/icon_star.png "alt=" Favorite Code "style=" border:0px; "/>
Public class Test {
Public Static void Main (string[] args) {
Test ();
Test (new string[]{"a"});
Test (new string[]{"A", "B"});
}
Private Static void Test () {
System.out.println ("[]");
}
Private Static void Test (string[] args) {
System.out.println (arrays.tostring (args));
}
}
The code after using the mutable parameter is downloaded as follows:
Java code 650) this.width=650; "class=" star "src=" Http://yizhenn.iteye.com/images/icon_star.png "alt=" Favorite Code "style=" border:0px; "/>
Public class Test {
Public Static void Main (string[] args) {
Test ();
Test (new string[]{"a"});
Test (new string[]{"A", "B"});
}
Private Static void Test (String ... args) {
System.out.println (arrays.tostring (args));
}
}
> We know that in Java everything is a class except for 8 basic types. So what kind of variable parameter is it? Come, use the code download Verify!
Java code 650) this.width=650; "class=" star "src=" Http://yizhenn.iteye.com/images/icon_star.png "alt=" Favorite Code "style=" border:0px; "/>
Public class Test {
Public Static void Main (string[] args) {
Whatclass ();
WhatClass1 ();
}
Private Static void whatclass (String ... args) {
System.out.println (Args.getclass ());
System.out.println (new string[]{}.getclass ());
}
Private Static void whatClass1 (int... args) {
System.out.println (Args.getclass ());
System.out.println (new int[]{}.getclass ());
}
}
The result of the above code is:
class [Ljava.lang.String;
class [Ljava.lang.String;
class [I
class [I
mutable parameters in Java