tags:

views:

776

answers:

3

For some reason one of my eclipse installations is ignoring incorrectly set @Override annotations. 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?

A: 
JRL
This isn't a missing @Override, it's a surplus-to-requirements-@Override!
banjollity
It's the opposite of what I'm looking for. There are @Override annotations that are already there when they shouldn't be, and cause compilation errors
Stephane Grenier
+3  A: 

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.

If that's not the problem here, then you'll need to provide some example code that shows which annotation you think should be flagged as an error (i.e. provide an SSCCE).

Joachim Sauer
Any idea how we can make it a compiler warning in 1.6?
Stephane Grenier
@Stephane: you can't. If you want a compiler warning for this you must select 1.5 compliance.
Stephen C
That's too bad because that's one of the annotations I really took advantage of.
Stephane Grenier
@Stephane: you can still do that. If you compile your project with Java 5 (i.e. set compiler level to Java 5 in Eclipse), it will still have the Java 5 semantics. Once you make the switch to Java 6 you'll have to consider the changes in semantics, however.
Joachim Sauer
+1  A: 

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