Co-Authored-By: Claude Sonnet 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_017ic4b66uwsWr9B1ouyrzUh
23 lines
793 B
Plaintext
23 lines
793 B
Plaintext
== what the JDK uses ==
|
|
"hello".hashCode() = 99162322
|
|
31*h + c over "hello" = 99162322
|
|
List.of(1,2,3).hashCode() = 30817
|
|
Arrays.hashCode({1,2,3}) = 30817
|
|
Objects.hash(1,2,3) = 30817
|
|
Set.of(1,2,3).hashCode() = 6 (sum of elements)
|
|
Map.of(1,2).hashCode() = 3 (key^value per entry, summed)
|
|
|
|
== Objects.hash(...) traps ==
|
|
Objects.hash("a") vs "a".hashCode() = 128 vs 97
|
|
Objects.hash(1, 2) == Objects.hash(2, 1) ? false
|
|
Objects.hash() (no args) = 1
|
|
Objects.hash((Object) null) = 31
|
|
|
|
== Arrays as fields ==
|
|
x.equals(y) = false, Arrays.equals = true
|
|
x.hashCode() == y.hashCode() ? false
|
|
Arrays.hashCode equal ? true
|
|
|
|
== equal hashCodes do not mean equal objects ==
|
|
"Aa".hashCode() = 2112, "BB".hashCode() = 2112, equal strings? false
|