equals-hashcode: equals/hashCode contract demos, missing hashCode and constant-hash costs, mutable keys, records, JPA entity id trap, 13 contract tests

Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_017ic4b66uwsWr9B1ouyrzUh
This commit is contained in:
Claude
2026-11-12 20:08:35 +05:30
parent 319697c345
commit 682b7b067c
22 changed files with 692 additions and 0 deletions
@@ -0,0 +1,15 @@
== equals() without hashCode() ==
a.equals(b) = true
a.hashCode() == b.hashCode() = false
HashSet size after adding a then b = 2
HashSet.contains(new equal key) = false
HashMap.get(equal key) = null
== with hashCode() ==
HashSet size after adding c then d = 1
HashSet.contains(new equal key) = true
== a legal but useless hashCode(): return 42 ==
keys = 2000
equals() calls for 2000 gets, constant hash = 2002999
equals() calls for 2000 gets, good hash = 2000