JDK 1.6 中的 @override 注释 [英] @override annotation in JDK 1.6

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

问题描述

我使用的是 JDK1.6.当我实现一个接口并在实现类中时,如果我在我的函数名称之前给出 @override,Eclipse 会抛出一个编译错误.即根据 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 */
}

如果我删除 @Override 注释,则代码编译正常.是不是说 JDK1.6 不再要求我们在 @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 中设置编译器合规性级别.这可以在 Window->Preferences->Java->Compiler

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

如果编译器首选项仍设置为 1.5,编译器将禁止覆盖注释.

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天全站免登陆