Java mutable parameter list

Source: Internet
Author: User

Java SE5 Adds a mutable parameter list attribute parameters can be defined like this, (Object...args). Variable parameters are defined with "...", and args is an array of mutable parameters. As an example:
Package sample; Class a{} public class Newvarargs {       static void PrintArray (Object...args) {for              (Object Obj:args)                     System.out.print (obj+ "");              System.out.println ();       }        public static void Main (string[] args) {              printArray (new Integer), New Float (3.14), New Double (11.11));              PrintArray (PrintArray ("One", "one", "one", "              three");              PrintArray (New A (), new A (), new A ());              PrintArray ((object[]) new integer[]{1,2,3,4});              PrintArray ();       }}

The output is:
3.14 11.113.14 11.11One and three[email protected] [email protected] [email protected]1 2 3 4
When a mutable parameter is specified, the compiler uses these arguments to populate a parameter array for a given variadic argument. This is why args can traverse with foreach. But if the parameter passed in itself is an array, the compiler will accept the array as a mutable parameter list, instead of wrapping the outer layer as a new array.

Java mutable parameter list

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.