@Override in eclipse

When one implements an interface, the template in Eclipse puts an @Override and it does not complain about it. Ant javac task also compiles without warnings.

Sometimes other Eclipse instances start to complain exactly for that @Override stating that there's no method that's overridden. Well, Eclipse, please do make up your mind.

http://java.sun.com/j2se/1.5.0/docs/api/java/lang/Override.html
"Indicates that a method declaration is intended to override a
method declaration in a superclass. If a method is annotated with
this annotation type but does not override a superclass method,
compilers are required to generate an error message."

Well, that's not very clear. As far as I remember an Interface is a pure abstract class, right? So, which one's correct.

P.S. Sometime ago I was having a similar problem with Eclipse and generics - Eclipse only gave a warning about something (can't remember what exactly), but the javac said that it was an error - Google said something like "eclipse uses jikes, you use javac". So what, aren't there specs?!

Update: apparently JDK5 (or 1.5, suit yourself) does not allow that. So in order to get all the wrong @Overrides - set the Compliance level to 5.0 (Eclipse -> Window -> Preferences -> Java -> Compiler -> Compiler compliance level ) - and..... correct them. I have 29 left.

12 thoughts on “@Override in eclipse”

  1. <blockquote>Well, Eclipse, please do make up your mind.</blockquote>
    In order for the Eclipse to make up their mind, it's crucial to report the problems you encounter in their bug tracking system.

    For me implementing a method is different than overriding one - so I don't write @Override when implementing a method from interface.

  2. When importing new source files, my Eclipse used to complain about those @Override things, if any. Setting compiler's compliance to 1.6 really solved the problem.

  3. The purpose of @Override is to guard against your changing the name of the overridden method in the super class, without realizing that the overriding method's name needs to be changed as well. From this point of view, it makes sense to use it when overriding a method from an interface; you want to make sure that you are going to be told, when renaming interface methods, about the methods implementing them that need to follow suit.

    So Eclipse is right to add @Override to methods overriding interface methods.

  4. I am using compliance 1.6 on Eclipse Galileo (3.5.1) and it still complains about @Overrides on interface methods. Bummer.

  5. The purpose of @Override is to guard against your changing the name of the overridden method in the super class, without realizing that the overriding method's name needs to be changed as well. From this point of view, it makes sense to use it when overriding a method from an interface; you want to make sure that you are going to be told, when renaming interface methods, about the methods implementing them that need to follow suit.

    So Eclipse is right to add @Override to methods overriding interface methods.

    I don't argue about that, but Rodrigo check this out:

    "Indicates that a method declaration is intended to override a method declaration in a superclass. If a method is annotated with this annotation type but does not override a superclass method, compilers are required to generate an error message."

    Source: http://java.sun.com/javase/6/docs/api/java/lang/Override.html

    So in my opinion two things should happen for @Override to be more usable - change its name to something else ('cause implementing an interface with @Override is a little stupid) and change the JavaDoc.

  6. Give please. Some are born great, some achieve greatness, and some hire public relations officers.
    I am from Lanka and learning to write in English, give please true I wrote the following sentence: "Casino royale, in chaos to its unique sound and quinine buyers, the share residence changes religious crude failure individuals."

    Waiting for a reply :), Pace.

  7. @Rodrigo
    You need to set your project level compliance level also-
    Project > properties > Java Compiler >

Leave a Reply

Your email address will not be published. Required fields are marked *

Notify me of followup comments via e-mail. You can also subscribe without commenting.

This site uses Akismet to reduce spam. Learn how your comment data is processed.