Contracts for Object Methods
Submit via Blackboard.
Assignment: Consider a simple, introductory Java inheritance example: Box and MatchBox.
equals()method in both classes. Use the "standard recipe" given in Bloch.
Boxis instantiable. Demonstrate this with an appropriate JUnit test. Which property is violated?
equals()method isn't more broken than necessary. Specifically, make sure that your implementation satisfies the other properties of the
hashCode(), also using Bloch's "standard recipe". Since
equals()is broken, hashCode() will also be broken. No JUnit test is required here.
hashCode()isn't more broken than necessary.
hashCodealong with failing JUnit test and description of the problem. You should also point out where you took special care with
hashCode()to avoid additional contract problems.