SWE 619 Assignment 10
Fall 2023


Goal: Object class contracts.

For this assignment, show what happens when objects with incorrect equals() implementations are stored in containers. Two different exercises; do both:

  1. Consider objects in Bloch's Point class where equals() is overridden with the standard recipe and hashCode() is not overridden at all. Build a (failing) JUnit test with a HashSet<Point> collection. The choice of anomaly is up to you. Explain clearly why the behavior you observe is incorrect.
  2. Consider objects in Bloch's Point and ColorPoint classes, where equals() is overridden with the standard recipe in both classes - and hence there is necessarily a symmetry problem. Override hashCode() in the Point class and simply inherit it in the ColorPoint class. Build another (failing) JUnit test case with a HashSet<Point> collection. Again, the choice of anomaly is up to you. Explain clearly why the behavior you observe is incorrect.