Try the following:
public class LooksLikePassByReference { public static void main(String[] args) { Properties properties = new Properties(); properties.setProperty("url", "www.google.com"); change(properties); System.out.println(properties.getProperty("url")); } public static void change(Properties properties2) { properties2 = new Properties(); properties2.setProperty("url", "www.yahoo.com"); } }
He prints "www.google.com".
In fact, you pass the value of the link, so the changes made to the object through this link will be visible. However, if you assign a new object reference for this parameter, this change will not be reflected, since you only passed the value of the link, not the actual reference to the variable.
source share