[J2SE 5.0 topics] [2.5] variable length parameters

Source: Internet
Author: User

As the name implies, variable length parameters refer to any number of parameters in the parameter body of a method. They are similar to object arrays. In J2SE 5.0, a new syntax is introduced, that is, adding... after the parameter type name indicates that this method can accept multiple parameters of this type. It must be noted that the variable length parameter must be placed at the end of the parameter list, and a method can only contain one such parameter.
Note that this syntax only works when declaring a method. When we implement this method, we usually do not write it like this, in this case, this parameter is used only as an Object in the method body. You cannot call this Object method to obtain an array of meaningful objects. Therefore, we usually use such a syntax when declaring a method, while using arrays in specific implementations. The compiler will handle this difference and treat them as signatures of the same method. See the following example:
Interface ITestVarargs {
Public void vararg (Object... args );
}
Class MyVarargs implements ITestVarargs {
Public void vararg (Object [] args ){
//...
}
}
In J2SE 5.0, another important new feature is based on variable length parameters, that is, formatting the output. I will explain it in more detail later.
For more information about variable length parameters, see here.

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.