Java mutable parameters

Source: Internet
Author: User
Java1.5 adds new features: variable parameters: For cases where the parameter number is indeterminate and the type is determined, Java handles the mutable parameter as an array. Note: The mutable parameter must be in the last item. When the number of mutable parameters is one more, there must be one that is not the last, so only one variable parameter is supported. Because of the variable number of arguments, Java cannot differentiate whether the passed parameter belongs to the previous variable parameter or the back parameter, so only the variable parameter can be placed in the last item, when there is the same type parameter behind it.
Features of variable parameters:
(1) can only appear at the end of the parameter list;
(2) ... Between the variable type and the variable name, there are no spaces before and after it can be;

(3) When a method of a variable parameter is called, the compiler creates an array for the mutable parameter implicitly, accessing the mutable parameter in the form of an array in the method body.

Example:

Print (string ... args) {for   (string Temp:args)      System.out.println (temp);}

Overwrite requirements:

(1) The overriding method does not reduce access rights;
(2) The parameter list must be the same as the overridden method (including the display form);
(3) The return type must be the same as or subclass of the overridden method;
(4) The overriding method cannot throw a new exception, or exceeds the scope of the parent class, but can throw fewer, more limited exceptions, or not throw exceptions.

Java mutable 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.