7

For some reason one of my eclipse installations is ignoring incorrectly set @Overrideannotations. For example, if I put @Override on a method that isn't overriden, it just completely ignores it.

Any ideas on how to bring it back to a state where it will display an error for an incorrectly annotated method?

Joachim Sauer
  • 302,674
  • 57
  • 556
  • 614
Stephane Grenier
  • 15,527
  • 38
  • 117
  • 192
  • Are you sure that eclipse has ever showed an error on extraneous @override annotations? – NomeN Sep 10 '09 at 20:13

3 Answers3

12

The definition of @Override changed slightly in Java 6 (and unfortunatly without proper documentation) wherein an @Override annotation on a method that implements an interface method is valid. In Java 5 that was considered an error.

Joachim Sauer
  • 302,674
  • 57
  • 556
  • 614
2

My theory is that your Eclipse is configured for JDK 1.6 compliance, but your Ant (or whatever) build is compiling with a JDK 1.5 compiler.

There was a change in the @Override annotation between JDK 1.5. and 1.6. In 1.5, it could only be used when a concrete method actually overrides a concrete method in a superclass. In JDK 1.6, it can also be used when the annotated method implements an abstract method defined in an interface or superclass.

The way to set Eclipse's compliance level is to open Windows>Preferences, select the Java>Compiler pane, and change the "Java Compiler Compliance" setting to 1.5. Then use Apply or OK to apply the preference change.

(AFAIK, there is no way to get Eclipse to give you 1.5 style warnings in 1.6 compliance mode.)

Stephen C
  • 698,415
  • 94
  • 811
  • 1,216
-1

The @override annotation was introduced in the JDK > 1.5.

On this machine would you be using an older version of the JDK by any chance?

JRL
  • 76,767
  • 18
  • 98
  • 146