@Override アノテーション
結城さんが匿名クラスと@Overrideで書いている記事に対してコメントしようと思ったけど、長くなってしまったのでこちらで。
結城さんの記事を読んで最初に思ったのは、interface のメソッドを「overrideする」とは言わないのではないか、と。言葉的にも「override」ではなく「implement」と呼ぶのが正しいのではないか、と。
なんとなく疑問に感じたので、Java言語仕様をチェックしてみた。すると、「9.6.1.4 Override」(アノテーションに関する部分)に、以下の記載があった。
Note that if a method overrides a method from a superinterface but not from a superclass, using @Override will cause a compile-time error.
The rationale for this is that a concrete class that implements an interface will necessarily override all the interface's methods irrespective of the @Override annotation, and so it would be confusing to have the semantics of this annotation interact with the rules for implementing interfaces.
A by product of this rule is that it is never possible to use the @Override annotation in an interface declaration.
言葉の意味とかじゃなくて、誤解を招かないようにするためなのね。