Co-Authored-By: Claude Sonnet 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_017ic4b4X2xx7RrveVQU9R1N
24 lines
799 B
Plaintext
24 lines
799 B
Plaintext
== 1. new ArrayList<>(list) and List.copyOf share the elements ==
|
|
boxes = [Box(100), Box(2)]
|
|
viaCtor = [Box(100), Box(2)]
|
|
viaCopyOf = [Box(100), Box(2)]
|
|
after boxes.add(Box(3)): viaCtor.size() = 2
|
|
|
|
== 2. The deep version needs the element copy, so a stream or a loop ==
|
|
boxes = [Box(-1), Box(2), Box(3)]
|
|
deep = [Box(100), Box(2), Box(3)]
|
|
|
|
== 3. HashMap copy constructor: new map, same values ==
|
|
mCopy.get("k") = Box(55)
|
|
|
|
== 4. 1-D primitive arrays: clone / copyOf are true copies ==
|
|
a = [99, 2, 3], clone = [1, 2, 3], copyOf = [1, 2, 3]
|
|
|
|
== 5. 2-D arrays: the rows are shared ==
|
|
grid = [[99, 2], [3, 4]]
|
|
shallow = [[99, 2], [3, 4]]
|
|
deepGrid = [[1, 2], [3, 4]]
|
|
|
|
== 6. Object arrays: copyOf copies references, not objects ==
|
|
arrCopy[0] = Box(77), same object: true
|