Your code does not compile, yet, because you are missing a return type in the Test() method. (which isn't used in this example). When I run the program I get:
Code:
I can't be changed once created
Now I have been changed
What I have understood from the immutability (spelling?) of a Java String object, is that the String itself will not change, but the reference to its value will. In contrast to the use of the reserved word 'final' which disallows an object to mutate its reference to its value.
Look at the text on wikipedia:
*** begin quote from http://en.wikipedia.org/wiki/Immutable_object ***
A classic example of an immutable object is an instance of the Java String class.
Code:
String s = "ABC";
s.toLowerCase();
The method toLowerCase() will not change the data "ABC" that s contains. Instead, a new String object is instantiated and given the data "abc" during its construction. A reference to this String object is returned by the toLowerCase() method. To make the String s contain the data "abc", a different approach is needed.
Code:
s = s.toLowerCase();
*** End Quote ***