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