Cloning in java String object

String very special type, which is immutable type, i.e., once initialized, will not be changed. Because he is a reference type, and he pointed to a constant value, cloned object changes his value
is actually changed the cloned to an object of type String members, will not affect the object being cloned.
Explanation: If a string variable when the original object is initialized, and points to a string constant, the string constants will be put into the constant pool,
reference will point to the string type of the constant. After cloning, get a new object, the object if the string variable re-assignment, then only
have this string reference variables point to a new area of memory, the original object string variables will not be affected.

Guess you like

Origin blog.csdn.net/reuxfhc/article/details/81590720