Java Pass by Value or Pass by Reference
public class Main { public static void main(String[] args) { Foo f = new Foo("f"); changeReference(f); // It won't change the reference! modifyReference(f); // It will modify the object that the reference variable "f" refers to! } public static void changeReference(Foo a) { Foo b = new Foo("b"); a = b; } public static void modifyReference(Foo c) { c.setAttribute("c"); } }Foo f = new Foo("f");public static void changeReference(Foo a)changeReference(f);Foo b = new Foo("b");
Last updated






