From my novice perspective of Java object, if two variables referencing one object, updating one variable should do the same to the other, as the code shows below:
SomeObject s1 = new SomeObject("first");
SomeObject s2 = s1;
s2.setText("second");
System.out.println(s1.getText()); // print second
System.out.println(s2.getText()); // print second as well
I referenced the code from this thread.
However, this doesn't apply to String class. See code below:
String s_1 = new String("first");
String s_2 = s_1;
s_2 = "second";
System.out.println("s_1: " + s_1 + " s_2: " + s_2);
//s_1 appears to be "first" and s_2 "second"
Is this because the difference between String class and self-declared class? Thank you for your help!