title: Any reason to prefer getClass() over instanceof when generating .equals()?
body: <p>I'm using Eclipse to generate <code>.equals()</code> and <code>.hashCode()</code>, and there is an option labeled "Use 'instanceof' to compare types".  The default is for this option to be unchecked and use <code>.getClass()</code> to compare types.  Is there any reason I should prefer <code>.getClass()</code> over <code>instanceof</code>?</p>
  
  <p>Without using <code>instanceof</code>:</p>
  
  <pre><code>if (obj == null)
    return false;
  if (getClass() != obj.getClass())
    return false;
  </code></pre>
  
  <p>Using <code>instanceof</code>:</p>
  
  <pre><code>if (obj == null)
    return false;
  if (!(obj instanceof MyClass))
    return false;
  </code></pre>
  
  <p>I usually check the <code>instanceof</code> option, and then go in and remove the "<code>if (obj == null)</code>" check. (It is redundant since null objects will always fail <code>instanceof</code>.)  Is there any reason that's a bad idea?</p>