在JDK 1.6 @Override注释 [英] @override annotation in JDK 1.6

查看:531
本文介绍了在JDK 1.6 @Override注释的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用JDK1.6。当我实现一个接口,并在实现类,如果我给 @override 在我的函数名,Eclipse将抛出一个编译错误。即低于code根据Eclipse是错误的。

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 */
}

如果我删除 @覆盖注释,那么,code编译罚款。这是否意味着JDK1.6并不需要我们preFIX的 @override 标注了?

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?

推荐答案

您可能需要设置在Eclipse编译器合规水平。这可以在窗口中找到 - > preferences-> Java的>编译器

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

如果编译器preferences仍设置为1.5编译器将在BARF覆盖注释。

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

编辑:还就每个项目的基础检查编译器合规性水平,如果你设置那些别的比默认

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

这篇关于在JDK 1.6 @Override注释的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆