Card 08/ 08

RecapDifficulty: Advanced1 min

Three Methods, One Contract, One Silent Failure

Five things this topic established, and where each one was.

What the topic established, and which card it was on
The thingWhere
Every class inherits equals, hashCode and toString with defaultsThe Three Methods Every Object Already Has
The default equals compares addresses, not contentsTwo Identical Orders That Java Says Are Not Equal
Equal objects must have equal hash codes; equal hash codes need not mean equal objectsThe Contract Between equals and hashCode
hashCode chooses the bucket; equals decides what was found in itFollowing One Key Into a HashMap
Override the two together, from fields that never changeWhy Changing a Key After Putting It In

The one worth carrying: breaking the contract throws nothing. It makes a value you stored impossible to find again and leaves size() insisting it is there, which is why this is worth getting right before anything depends on it.