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
+23
View File
@@ -0,0 +1,23 @@
== generated equals/hashCode ==
a.equals(b) = true
a.hashCode() == b.hashCode() = true
new HashSet of both, size = 1
a == b = false
== array component: reference equality ==
w1.equals(w2) = false
same array shared: true
== mutable List component: equals works, hashCode can change ==
hashCode before = 4714, after list.add(3) = 34537
record in HashSet, list mutated -> contains = false
== doubles compare with Double.compare semantics ==
NaN record equals NaN record = true
Double.NaN == Double.NaN = false
0.0 record equals -0.0 record = false
0.0 == -0.0 = true
== overriding equals in a record ==
t1.equals(t2) = true
toString still shows both fields: Tagged[isbn=1, title=Effective Java 3e]