Java mutable Parameter Object ... values

Source: Internet
Author: User

Public list<?> Find (final String queryString, final Object ... values) throws DataAccessException

Methods for defining the variable number of arguments
Simply add three consecutive "." Between "type" and "parameter name" of a formal parameter. (That is, "...", an ellipsis in an English sentence), it can be matched to an indeterminate argument. A method with such a parameter is a variable number of arguments.

Listing 1: A method with a variable number of arguments

  1. Private Static intSumUp (int... values) {    

  2. }

  1. Private Static intSumUp (int... values) {   

  2. }

Note that only the last formal parameter can be defined as "can and does not have an argument to match". Therefore, there can be only one such parameter in a method. Also, if the method has other parameters, put them in the front position.

The compiler converts the last parameter into an array parameter behind the box and makes a tick in the compiled class file, indicating that this is a variable number of arguments.

Listing 2: Secret form of methods with variable number of arguments

  1. Private Static intSumUp (int[] values) {    

  2. }

  1. Private Static intSumUp (int[] values) {   

  2. }

Because of this transformation, it is no longer possible to define a method that is consistent with the converted method signature for this class.

Reference post: http://www.cnblogs.com/shishm/archive/2012/01/31/2332656.html

Java mutable Parameter Object ... values

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.