Classes that define an equals method whose parameter type is not Object overload the Object.equals method instead of overriding it. This may not be intended.

To override the Object.equals method, the parameter of the equals method must have type Object.

In the following example, the definition of class BadPoint does not override the Object.equals method. This means that p.equals(q) resolves to the default definition of Object.equals and returns false. Class GoodPoint correctly overrides Object.equals, so that r.equals(s) returns true.

  • J. Bloch, Effective Java (second edition), Item 8. Addison-Wesley, 2008.
  • The Java Language Specification: Overriding (by Instance Methods), Overloading.
  • The Java Tutorials: Overriding and Hiding Methods.