Witscale Test Center

14.6 Overriding the equals() and hashCode() methods


14.6 Overriding the equals() and hashCode() methods

The equals() and hashCode methods are defined in java.lang.Object. Since all Java classes extend Object they inherit these methods. However many classes override these two methods instead of using the default implementation that java.langObject provides. In the following sections we will see why we need to override these methods and how to correctly override them