[Problem log] Java about mutable parameter overloading problems

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.