» @Override Idiosyncrasies #

Paul R. Brown @ 2008-11-19

Just to prove that you frequently learn something new about a language you're familiar with, I recently learned that the following will compile on JDK6:

interface I {
  void m();
class C implements I {
  public m() {

(It even compiles on JDK6 with -source 1.5, which seems like a bug under the circumstances, but no matter.)

I'm sure that this was discussed ad nauseum by the JSR-175 expert group and then subsequently when @Override behavior was overridden for JDK6, but this seems wrong if you ask me. (I'd argue that the JLSv3 concurs.) The @Override annotation, under the JDK5 interpretation, indicates the replacement piece of code in the superclass, along with all of its side-effects. Implementing a method on an interface does not change behavior and requires no more attention from the developer than an understanding of the contract that the interface represents. If anything, an @Implements annotation would have been a better choice than mucking up the @Override annotation to better align with the murky definition of overriding in the JLS.

To make things more confusing, the current JDK6 documentation is incorrect. The JDK6 API documentation says the same thing as the JDK5 documentation does, but JDK7 API documentation describes the JDK6 behavior.


← 2008-11-14 — Binding nxml-complete in Aquamacs Emacs
→ 2008-11-23 — Three Jokes about Mathematicians