copying: deep vs shallow copy module (clone() traps, copy constructors, serialization copy, records, defensive copies, collection copies), 17 contract tests
Co-Authored-By: Claude Sonnet 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_017ic4b4X2xx7RrveVQU9R1N
This commit is contained in:
@@ -0,0 +1,10 @@
|
||||
== 1. Copy constructor: new object, own list, final fields intact ==
|
||||
rex = Dog(Rex, [sit, roll]) bark=7
|
||||
rex2 = Dog(Rex, [sit, roll]) bark=7
|
||||
rex2.tricks == rex.tricks : false
|
||||
|
||||
== 2. The static type picks the constructor, so a subtype is sliced off ==
|
||||
new Animal(pet) = Animal(Rex, [sit, roll])
|
||||
|
||||
== 3. A virtual copy() keeps the runtime type ==
|
||||
pet.copy() = Dog(Rex, [sit, roll]) bark=7
|
||||
Reference in New Issue
Block a user