Java overloaded methods with deformable parameters

Source: Internet
Author: User

If you overload a method with a deformable parameter, you need to be aware that

public class Overloadvarargstest{public void Test (String msg) {System.out.println ("only one string parameter of the test Method");} Overloaded method with deformable parameter public void Test (String ... books) {SYSTEM.OUT.PRINTLN ("* * * parameter variable test method ********");} public static void Main (string[] args) {Overloadvarargs ov=new Overloadvarargs (); Ov.test ();//execution of the first test method Ov.test (" Java programming Idea "," Java Core technology volume ");//Executes the second ov.test (" Nihao ");//Executes the first test method Ov.test (new string[]{" AA "," BB "});//Executes the second Test method}}

In addition, overloading of variable-parameter methods is not recommended because it can reduce the readability of your code!!!

Java overloaded methods with deformable parameters

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.