I. review some typical Java value transfer and address (reference transfer) problems.
In Java, is there only one-value transfer method or two methods: value transfer and reference transfer. So far, it is still not a confirmation issue, and most of the controversial issues do not necessarily require confirmation. However, the people we learn must understand the relationship and make accurate judgments, use, and read the transfer in the program.
The following is an example:
Package net. mldream. day2; Class valhold {public int I = 10;} public class obparm {public static void main (string [] ARGs) {// todo auto-generated method stubobparm o = new obparm (); O. amethod ();} public void amethod () {int I = 99; valhold v = new valhold (); V. I = 30; another (V, I); system. out. print (v. i);} // end of amethodpublic void another (valhold V, int I) {I = 20; V. I = 20; valhold VL = new valhold (); V = VL; system. out. print (v. i); system. out. print (I);} // end of another}
The result of this program is: 10020
A simple summary: The value transfer is of course equivalent to passing the value size of the real parameter to the form parameter without modifying the original space memory, real parameters and form parameters are two different buckets. Therefore, modifications to the form parameter within the function cannot change the value of the original real parameter variable.
The so-called reference transfer can be understood as the transfer of a piece of space, the first address of a Data Structure (storage block) (because the first address often represents a piece of space memory ), it usually contains the principle that, when a function is inside, it changes, and the function is restored after it is introduced. That is, change in progress and restore in return.