public class Main {
public static void main(String[] args) {
Foo f = new Foo("f");
System.out.println(f.string);
changeReference(f); // It won't change the reference!
modifyReference(f); // It will modify the object that the reference variable "f" refers to!
System.out.println(f.string);
}
// 값에 의한 호출
public static void changeReference(Foo a) {
Foo b = new Foo("b");
System.out.println(b.string);
a = b;
System.out.println(a.string);
}
// 주소에 의한 호출
public static void modifyReference(Foo c) {
c.setAttribute("c");
System.out.println(c.string);
}
}
// f
// b
// b
// c
// c