Cloning is copying a copy of an object, and cloning is a shallow clone and a deep clone. Shallow cloning means that the value of the base type of the cloned object has changed, and the value of the source object does not change. However, if the value of the reference type of the cloned object changes, the value of the source object is also changed because the reference type holds a reference address in the stack memory, and the object is cloned to the same memory space as the reference address of the source object. So at the time of cloning, any change in the value of any object will change the value of the other, so deep cloning will be used in this case.
Note that the tears of the objects to be cloned must inherit the Cloneable interface. The characteristic of shallow cloning is to clone only the object ontology, its advantages and disadvantages is a change of all; deep cloning is a new object, and the source object is not interfering with each other, and its advantages and disadvantages are non-interference and trouble. Usually we use only shallow clones when cloning is used.
Cloning can be easily understood as: When cloning an object, the value of the property and methods are copied together is a shallow copy, and the value of the method can be set different is a deep clone. Deep cloning to instantiate, first output the content to memory, and then read from memory.
Java cloning--the difference between deep cloning and shallow cloning