<p>
"equals" as a method name should be exclusively used to override <code>Object.equals(Object)</code> to prevent any confusion.
</p>

<p>
It is tempting to overload the method to take a specific class instead of <code>Object</code> as parameter, to save class comparison check.
However, this will not work as expected.
</p>

<p>For example:</p>

<pre>
class MyClass {
  private int foo = 1;

  public boolean equals(MyClass o) {                    // Non-Compliant - "equals" method which does not override Object.equals(Object)
    return o != null && o.foo == this.foo;
  }

  public static void main(String[] args) {
    MyClass o1 = new MyClass();
    Object o2 = new MyClass();
    System.out.println(o1.equals(o2));                  // Will display "false" because "o2" is of type "Object" and not "MyClass"
  }
}
</pre>

<p>should be refactored into:</p>

<pre>
class MyClass {
  private int foo = 1;

  @Override
  public boolean equals(Object o) {                     // Compliant - overrides Object.equals(Object)
    if (o == null || !(o instanceof MyClass)) {
      return false;
    }

    MyClass other = (MyClass)o;
    return this.foo == other.foo;
  }

  /* ... */
}
</pre>