Card 08/ 08
All 8 cards
RecapDifficulty: Advanced1 min
Three Methods, One Contract, One Silent Failure
Five things this topic established, and where each one was.
| The thing | Where |
|---|---|
Every class inherits equals, hashCode and toString with defaults | The Three Methods Every Object Already Has |
The default equals compares addresses, not contents | Two Identical Orders That Java Says Are Not Equal |
| Equal objects must have equal hash codes; equal hash codes need not mean equal objects | The Contract Between equals and hashCode |
hashCode chooses the bucket; equals decides what was found in it | Following One Key Into a HashMap |
| Override the two together, from fields that never change | Why 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.