11

In Eclipse 3.4.1 using JDK1.6.0_10 how can I activate a warning on a missing @Override annotation on a method that implements an interface method?

In the Preferences window this option:

Java > Compiler > Errors / Warnings > Annotations > Missing '@Override' annotation

works fine for missing annotations on methods that override a superclass method, but it does nothing for interface methods.

Craig Angus
  • 22,784
  • 18
  • 55
  • 63
Benno Richters
  • 15,378
  • 14
  • 42
  • 45
  • 1
    Java 5 and Java 6 have different expectations about @Override annotations on interface implementations. I don't recall how this impacts Eclipse, but I know that it does. – Bill Michell Oct 22 '08 at 09:31
  • I should have mentioned this. Added the version of Java (6) to the question. – Benno Richters Oct 22 '08 at 09:55

4 Answers4

10

It is not possible in Eclipse 3.4.1. It is a known issue. See this bug report page for more information.

Benno Richters
  • 15,378
  • 14
  • 42
  • 45
2

Belay what I said in the other thread. Apparently it's not a compiler option, but a Java compatibility version issue: if your compatibility version is 5, you won't be able to annotate interface implementation methods. If your compatibility version is 6, then you will be able to.

However I don't think there's a way of actually forcing Eclipse to generate an error if you do not annotate each implemented method. From this page:

Missing '@Override' annotation: When enabled, the compiler will issue an error or a warning whenever it encounters a method overriding another implemented method, and the '@Override' annotation is missing.

1

The compatibility setting to 1.6 instead of 1.5 worked for me on: Eclipse Java EE IDE for Web Developers.

Build id: 20100218-1602

EMR
  • 31
  • 4
0

Maybe I'm missing something but interface methods are already required to be implemented by implementation classes.

The compiler will generate an error if the interface is not completely implemented.

fhe
  • 6,099
  • 1
  • 41
  • 44
  • Yes, but you still want this. See http://stackoverflow.com/questions/212614/should-a-method-that-implements-an-interface-method-be-annotated-with-override – Benno Richters Oct 22 '08 at 09:17
  • Ah yes, thanks for the pointer. Must have missed that since I'm still at Java 1.5 on Mac OSX :-) – fhe Oct 22 '08 at 10:54