Loading lesson…
Level 1 · Apprentice0 XP
Why a HashSet loses your object, and the contract that prevents it.
Step 1 / 5
ProblemYou put a user in a HashSet and then ask whether it contains an identical user. It says no. The class overrode equals but forgot hashCode.
← → step
Before this: Records and immutability
🛠️ Your turn
Reading is not the skill, doing is. Try for ten minutes before you open the hint. Getting stuck first is what makes the solution stick.
1.Write a class Point with equals but no hashCode. Add one to a HashSet and show contains() returns false for an equal point. Then fix it two ways: by hand and by turning it into a record.