Rational Developer for System z

Shallow copying and deep copying

The terms shallow copy and deep copy describe two different ways of copying an element.

Shallow copy: A shallow copy creates a duplicate of the original element (whether simple or complex) but does not make copies of any elements referenced by the original element. Instead, if the original element contains a reference to an object, then the corresponding reference in the copied element refers to the same object.

Deep copy: A deep copy copies not only the original element but also any elements referenced by the original element. For each reference in the original element, the copy operation creates a new instance of the referenced object, copies the contents of the referenced object into the new instance of the object, and stores a reference to the new instance of the object into the new element.

Referenced objects that themselves contain references are copied in the same way.


Feedback