Override equals() + hashCode()
OFF = default (compare by reference) · ON = compare by valueOFF · identity
two Point objectsedit a coord to make them differ
p1@0x1A
hashCode()—
p2@0x2B
hashCode()—
identity checkslive
p1 == p2reference equality — same object?false
p1.equals(p2)value equality — same contents?false
hashCode() matchdo the two hashes agree?false
HashSet<Point>add → bucket → equals
set.size()0
console
▸With the override OFF, two equal points sneak into the set as duplicates (size 2). Flip it ON so equals + hashCode agree — the duplicate is caught (size 1).