views:

200

answers:

5

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?

+8  A: 

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.

Gennadiy
A: 

JDK1.6 definitely supports it. I'm not sure why you would have issues.

What error are you seeing? The only thing I can think of is to make sure that you are using the correct JDK in your project settings. Maybe you are compiling against an older JDK?

Riaan Cornelius
This should be a comment to the question.
Jacob Tomaw
A: 

No the @Override annotation is still used. You should check that the contextDestroyed method is really present in the ServletContextListener interface, and check the imported package for this interface.

Manuel Selva
A: 

It sounds like your compiler is set for Java 5, when @Override on interfaces wasn't allowed.

Noel M