I’ve always wondered why Java 5 was not consistent with @Override annotation type. Today after experiencing the compilation failure again I digged further. The problem:

abstract class Rectangle {
   abstract double getArea();
}
// deriving from abstract class
class Square extends Rectangle {
   @Override
   double getArea() {
      // ...
   }
}

interface Shape {
   double getArea();
}
// implementing an interface
class Square implements Shape {
   @Override
   // Java5 will complain about @Override
   // "method does not override a method from its superclass"
   double getArea() {
      // ...
   }
}

Java compiler will complain about @Override being used yet no such method in parent “method does not override a method from its superclass”? Well, the compiler is wrong as there is such method in parent, but instead of a superclass it is a supertype of an interface.

Luckily Java6 recognized the issue and fixed it. Not sure why this has not been implemented in a first place.