Class EqualsHashCodeCheck

  • All Implemented Interfaces:
    Configurable, Contextualizable

    public class EqualsHashCodeCheck
    extends AbstractCheck

    Checks that classes that either override equals() or hashCode() also overrides the other. This checks only verifies that the method declarations match Object.equals(Object) and Object.hashCode() exactly to be considered an override. This check does not verify invalid method names, parameters other than Object, or anything else.

    Rationale: The contract of equals() and hashCode() requires that equal objects have the same hashCode. Hence, whenever you override equals() you must override hashCode() to ensure that your class can be used in collections that are hash based.

    An example of how to configure the check is:

     <module name="EqualsHashCode"/>
     
    Author:
    lkuehne