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,15 @@
|
||||
== 1. A record does not copy the list you give it ==
|
||||
leaky.items() = [pen, book, laptop]
|
||||
after leaky.items().add("phone"), basket = [pen, book, laptop, phone]
|
||||
|
||||
== 2. List.copyOf in the compact constructor ==
|
||||
safe.items() = [pen, book]
|
||||
safe.items().add(...) -> UnsupportedOperationException
|
||||
|
||||
== 3. 'Changing' a record means building a new one ==
|
||||
safe = SafeOrder[id=A-2, items=[pen, book]]
|
||||
bigger = SafeOrder[id=A-2, items=[pen, book, charger]]
|
||||
|
||||
== 4. A mutable Date component ==
|
||||
LeakyEvent.when().getTime() after caller mutates d1 = 86400000
|
||||
SafeEvent.when().getTime() after both mutations = 0
|
||||
Reference in New Issue
Block a user