An analysis of the problem of integer parameter _java in Java

Source: Internet
Author: User

Java itself is a value-transitive invocation, and an address value is passed on to an object. Assigning a value to an address value is equal to pointing back, without affecting the outer layer.
And here the integer object also has particularity. may be similar in its implementation

Copy Code code as follows:

Class integer{
final int value; Once you assign a value, you cannot change it.
}

This occurs:The address value of the call newsletters cannot change the outer + object itself. Cause this value can't be changed

Many solutions
1,
Java style is that a single value with the return value. return i; to I=foo (); Assign a value; Multiple values with an array or object.
2, the delivery of their own packaging classes. class mutableinteger{int value;}
3, the transfer of special Atomicinteger Atomic integer Object

Copy Code code as follows:

public static void Main (string[] parameter) {
Atomicinteger i=new Atomicinteger (40);
I.intvalue ();
System.out.println (i);
}
public static void Change (Atomicinteger i) {
I.set (55);
}

can also be implemented after the transfer of value,
recommended option 1, try to avoid

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.