Suddenly found that Java variable parameter overload is ambiguous, but do not know how to handle the internal Java, specifically to do the following experiments:
The test code is as follows:
1 /**2 * Created by Ieayoio on 16-3-1.3 */4 Public classVartest {5 6 Public Static voidaaaint... a) {7SYSTEM.OUT.PRINTLN ("Variable parameter overloading");8 }9 Ten Public Static voidaaainta) { OneSYSTEM.OUT.PRINTLN ("Non-volatile parameter overloading"); A } - Public Static voidMain (string[] args) { - the } -}
1. Add AAA () on line 14 and run the result as follows:
Variable parameter overloading
Process finished with exit code 0
2. Add AAA (111,111) on line 14 and run the result as follows:
Variable parameter overloading
Process finished with exit code 0
3. Add AAA (111) On line 14 and run the result as follows:
Non-volatile parameter overloading
Process finished with exit code 0
4. Change the code to the following:
1 /**2 * Created by Ieayoio on 16-3-1.3 */4 Public classVartest {5 6 Public Static voidaaainta) {7SYSTEM.OUT.PRINTLN ("Non-volatile parameter overloading");8 }9 Ten Public Static voidaaaint... a) { OneSYSTEM.OUT.PRINTLN ("Variable parameter overloading"); A } - - Public Static voidMain (string[] args) { theAAA (111); - } -}
The result remains:
Non-volatile parameter overloading
Process finished with exit code 0
Conclusion: When using the variable-parameter overloading method, the non-mutable parameter method is preferred to execute the program within Java.
Original link: http://www.cnblogs.com/ieayoio/p/5231751.html
[Problem log] Java about mutable parameter overloading problems