Goal:
The contract for equals()
.
As it happens, Liskov's discussion of equals()
for the Point2
and Point3
classes (see section 7.9.3, page 182)
is wrong.
Point2
and Point3
that you can instantiate
Point2
and Point3
objects.
NewPoint3
that has a Point2
object as an instance variable
(that is, use composition instead of inheritance.)
equals()
and hashCode()
for both Point2
and NewPoint3
.
Use Bloch's recipe.
equals()
violates its contract for the
Point2
, Point3
combination.
Point2
, NewPoint3
combination.