Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

@override annotation in JDK 1.6

I'm using JDK1.6. When I implement an interface and in the implementing class, if I give @override before my function names, Eclipse throws an compilation error. i.e. below code is wrong according to Eclipse.

public class SomeListener implements ServletContextListener {
    @Override
    public void contextDestroyed(ServletContextEvent arg0) {
       // code
    }
    /* other overridden methods here */
}

If I remove @Override annotation, then the code compiles fine. Does it mean that JDK1.6 does not require us to prefix the @override annotation anymore?

like image 866
Veera Avatar asked Sep 01 '10 14:09

Veera


2 Answers

You probably need to set the compiler compliance level in eclipse. This can be found in Window->Preferences->Java->Compiler

If the compiler preferences are still set to 1.5 the compiler will barf on the override annotation.

Edit: Also check compiler compliance level on a per project basis if you've set those to anything else than default.

like image 68
Gennadiy Avatar answered Nov 15 '22 15:11

Gennadiy


@Override works on method implementation since java 1.6.


Resources :

  • Sun's forums - Java Programming - Should @Override apply to implementation of interface/abstract methods?
  • dertompson.com - @Override specification changes in Java 6
  • The Former Weblog of Peter Ahé - @Override snafu

On the same topic :

  • When do you use Java's @Override annotation and why?
like image 32
Colin Hebert Avatar answered Nov 15 '22 15:11

Colin Hebert