title: What is "override-equivalence" and how is it related to @Override?
body: <p>Reading the <a href="http://docs.oracle.com/javase/7/docs/api/java/lang/Override.html" rel="nofollow noreferrer">Javadoc</a> for the <code>@Override</code> annotation, I came across the following rule:</p>
  <blockquote>
  <p>If a method is annotated with this
  annotation type compilers are required to generate an error message
  unless at least one of the following conditions hold:</p>
  <ul>
  <li>The method does override or implement a method declared in a supertype.</li>
  <li><strong>The method has a signature that is override-equivalent to that of any public method
  declared in Object.</strong></li>
  </ul>
  </blockquote>
  <p>I'm clear on the first point, but I'm unsure about the second one.</p>
  <p>What does it mean by &quot;override-equivalent&quot;? How are public methods of <code>Object</code> special in this respect? And why is this not covered under the first criterion?</p>
  <p>Moreover, this is only true of the Java 7+ documentation. The <a href="http://docs.oracle.com/javase/6/docs/api/java/lang/Override.html" rel="nofollow noreferrer">Java 6 doc</a> doesn't say anything about override-equivalence. Why the change?</p>
  <hr />
  <h2>Update:</h2>
  <p>After further consulting the JLS (<a href="http://docs.oracle.com/javase/specs/jls/se7/html/jls-8.html#jls-8.4.2" rel="nofollow noreferrer">Section 8.4.2</a>), I found the following explanation of override-equivalence:</p>
  <blockquote>
  <p>The signature of a method <code>m1</code> is a <em>subsignature</em> of the signature of a method <code>m2</code> if
  either:</p>
  <ul>
  <li><code>m2</code> has the same signature as <code>m1</code>, or</li>
  <li>the signature of <code>m1</code> is the same as the erasure (<a href="http://docs.oracle.com/javase/specs/jls/se7/html/jls-4.html#jls-4.6" rel="nofollow noreferrer">§4.6</a>) of the signature of <code>m2</code>.</li>
  </ul>
  <p><strong>Two method signatures <code>m1</code> and <code>m2</code> are <em>override-equivalent</em> iff either <code>m1</code> is a
  subsignature of <code>m2</code> or <code>m2</code> is a subsignature of <code>m1</code>.</strong></p>
  </blockquote>
  <p>As far as I can tell, this answers the first question (&quot;What does it mean?&quot;) and the third question (&quot;Why doesn't the first condition cover this?&quot;).</p>
  <p>If I understand correctly (please inform me if I don't!), there is only one case where two methods are override-equivalent and which <em>doesn't</em> fall under the first condition of the original question. This is the case when the <em>erasure</em> of the signature of the subclass method is the same as the signature of the superclass method, but not the other way around.</p>
  <p>The second condition of the original question, then, would only come into play when we attempt to add type parameters when attempting to &quot;override&quot; a public method of the <code>Object</code> class. I tried the following simple example to test this, with an unused type parameter:</p>
  <pre><code>public class Foo {
      @Override
      public &lt;T&gt; boolean equals(Object obj) {
          return true;
      }
  }
  </code></pre>
  <p>Of course, this class doesn't compile, because the method doesn't <em>actually</em> override the <code>equals</code> method and thus clashes with it. But I also still receive a compiler error for using the <code>@Override</code> annotation. Am I wrong in assuming that this example meets the second condition for <code>@Override</code> usage? Or is the compiler generating this error <em>despite not being required to</em>?</p>