String immutability

In java immutable defined as: If you have created an object, its state can not be changed. That is not to change the object's member variables, including the value of the basic type can not be changed, a reference type variable can not point to other objects, state the type of the object pointed reference also
can not be changed.
The reason immutable: jdk1.8 in String member variables char [] value, hash value, etc. in addition to other member variables are not modified. And the value is modified on the surface, since each method is able to modify the new value in
a String object returned. However, you can modify the member variables in String through reflection.

Guess you like

Origin blog.51cto.com/3544011/2402043