title: Java .equals() instanceof subclass? Why not call superclass equals instead of making it final?
body: <p>It is stated in Object's <code>.equals(Object)</code> javadoc:</p>
  
  <blockquote>
    <p>It is symmetric: for any non-null reference values x and y,
    x.equals(y) should return true if and only if y.equals(x) returns
    true.</p>
  </blockquote>
  
  <p>Almost everywhere in example code I see overridden <code>.equals(Object)</code> method which uses <code>instanceof</code> as one of the first tests, for example here: <a href="https://stackoverflow.com/questions/27581/overriding-equals-and-hashcode-in-java">What issues / pitfalls must be considered when overriding equals and hashCode?</a></p>
  
  <pre><code>public class Person {
      private String name;
      private int age;
  
      public boolean equals(Object obj) {
          if (obj == null)
              return false;
          if (obj == this)
              return true;
          if (!(obj instanceof Person))
              return false;
          ...
      }
  </code></pre>
  
  <p>}</p>
  
  <p>Now with <code>class SpecialPerson extends Person</code> having in <code>equals</code>:</p>
  
  <pre><code>        if (!(obj instanceof SpecialPerson))
              return false;
  </code></pre>
  
  <p>we con not guarantee that <code>.equals()</code> is symmetric.
  It has been discussed for example here: <a href="https://stackoverflow.com/a/596507/2622016">any-reason-to-prefer-getclass-over-instanceof-when-generating-equals</a></p>
  
  <pre><code>Person a = new Person(), b = new SpecialPerson();
  
  a.equals(b);    //sometimes true, since b instanceof Person
  b.equals(a);    //always false
  </code></pre>
  
  <p>Maybe I should add in the beginning of SpecialPerson's equals direct call to super?</p>
  
  <pre><code>    public boolean equals(Object obj) {
          if( !obj instanceof SpecialPerson )
              return super.equals(obj);
          ... 
          /* more equality tests here */
      }
  </code></pre>