Companion code for the ankurm.com post "Top 40 Java Collections Interview Questions (HashMap Internals to Fail-Fast Iterators)". Verified against JDK 25's own HashMap source (TREEIFY_THRESHOLD=8, UNTREEIFY_THRESHOLD=6, MIN_TREEIFY_CAPACITY=64), with every claim backed by a committed docs/output/*.txt transcript from a real run. Co-Authored-By: Claude Sonnet 5 <[email protected]> Claude-Session: https://claude.ai/code/session_01YXCrLgRKFgCh9RHKW8xaqJ
9 lines
696 B
Plaintext
9 lines
696 B
Plaintext
Mutating a key's hash-relevant field after insertion: the entry is still THERE, just unfindable
|
|
===============================================================================================
|
|
|
|
map.put(key(tag=42), ...) then key.setTag(99)
|
|
containsKey(new MutableKey(42)) before mutation : true
|
|
containsKey(new MutableKey(42)) after mutation : false (looks for old hash's bucket - key no longer hashes there)
|
|
containsKey(new MutableKey(99)) after mutation : false (looks in the NEW hash's bucket - key was never filed there either)
|
|
map.size() is still : 1 (the entry was never removed!)
|
|
the mutated key object IS still found by direct iteration over keySet(): true |