The so-called reference transfer refers to the use of the heap memory space to multiple stack memory space
Example <1>
public class Aliasing {int temp = 30;public static void Main (string[] args) {//TODO auto-generated method stub aliasing D1 = new aliasing () ;d 1.temp = 50; System.out.println (d1.temp); fun (D1); System.out.println (d1.temp);} public static void Fun (aliasing D2) {d2.temp = 1000;}}
Example <2> it is passed a string object, because the contents of string is not modifiable, so the value of str1 or Hello, if passed is the object's string property, it can be modified
public class Aliasing {int temp = 30;public static void Main (string[] args) {//TODO auto-generated method stub String str1 = "Hello"; System.out.println (STR1); fun (STR1); System.out.println (STR1);} public static void Fun (String str2) {str2 = "Hello2";}}
Example <3> passing is the string property of the object
public class Aliasing {String temp = "Hello";p ublic static void Main (string[] args) {//TODO auto-generated method stub aliasing D1 = new Al Iasing ();d 1.temp = "World"; System.out.println (d1.temp); fun (D1); System.out.println (d1.temp);} public static void Fun (aliasing D2) {d2.temp= "HELLO";}}
Java Reference Mechanism--aliasing