Add three points after the java function parameter type

Source: Internet
Author: User

Today, I saw a list of function parameters test (int...,
The original usage is as follows:

The following three vertices of the type (String...) Start from Java 5. the Java language supports a new method for method parameters,
It is called the variable length parameter list. Its syntax is the type followed by..., indicating that the parameters accepted here are 0 to multiple objects.
Type Object, or an Object []. For example, we have a method named test (String... strings ),
You can also write the test () method, but you cannot write test (String [] strings). This will cause a compilation error,
The system prompts a duplicate method.
When using test (String... strings), you can use test () to call it directly, indicating that no
You can also use test ("aaa") or test (new String [] {"aaa", "bbb "}).
In addition, if both the test (String... strings) function and the test () function exist, when we call test,
The test () function is used first. Only when we call test () without the test () function will the program go through
Test (String... strings ).
Example:

Public class Ttest {// private static int a; public static void test (int... a) {for (int I = 0; I <. length; I ++) {System. out. println (a [I]) ;}} public static void main (String [] args) {Ttest. test (1, 2 );}}

Source: http://hi.baidu.com/8741659422/blog/item/a1f3384c2035a3edd72afc3e.html

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.