🔵 🔵 🔵


Primary

၊၊||၊|။

Shallow Copy ○|Definition|1st|20260122172742-00-⌔

Object copying - Wikipedia#Shallow_copy

Shallow copy

🖼️ ➺

Variable reference to different memory space

🖼️ ➺

The assignment of variable B to A.

🖼️ ➺

Variables referring to same area of memory.

One method of copying an object is the shallow copy. In that case a new object B is created, and the fields values of A are copied over to B.123 This is also known as a field-by-field copy,456 field-for-field copy, or field copy.7 If the field value is a reference to an object (e.g., a memory address) it copies the reference, hence referring to the same object as A does, and if the field value is a primitive type, it copies the value of the primitive type. In languages without primitive types (where everything is an object), all fields of the copy B are references to the same objects as the fields of original A. The referenced objects are thus shared, so if one of these objects is modified (from A or B), the change is visible in the other. Shallow copies are simple and typically cheap, as they can usually be implemented by simply copying the bits exactly.

Printed 2026-06-28.

(echo:: @ )

Footnotes

  1. “C++ Shallow vs Deep Copy Explanation”. Archived from the original on 2014-02-10. Retrieved 2013-04-10.

  2. ”.NET Shallow vs Deep Copy Explanation”.

  3. “Generic Shallow vs Deep Copy Explanation”. Archived from the original on 2016-03-04. Retrieved 2013-04-10.

  4. Core Java: Fundamentals, Volume 1, p. 295

  5. Effective Java, Second Edition, p. 54

  6. “What is this field-by-field copy done by Object.clone()?”, Stack Overflow

  7. “Josh Bloch on Design: A Conversation with Effective Java Author, Josh Bloch”, by Bill Venners, JavaWorld, January 4, 2002, p. 13

Link to original

Secondary

• • •