为什么Eclipse的抱怨@Override接口的方法呢? [英] Why does Eclipse complain about @Override on interface methods?

查看:189
本文介绍了为什么Eclipse的抱怨@Override接口的方法呢?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个使用 @覆盖上覆盖的接口的方法,而不是超类方法方法,现有的项目。我不能在code改变这个,但我想Eclpse停止抱怨的注解,因为我仍然能够与Maven构建。

I have an existing project that uses @Override on methods that override interface methods, rather than superclass methods. I cannot alter this in code, but I would like Eclpse to stop complaining about the annotation, as I can still build with Maven.

我怎么会去禁用这个错误?

How would I go about disabling this error?

注意:由于项目要求,我需要编译的Java 1.5

推荐答案

使用 @覆盖标注上实现这些宣布一个接口只能从Java 6的有效方法向前。这是Java 5中的错误。

Using the @Override annotation on methods that implement those declared by an interface is only valid from Java 6 onward. It's an error in Java 5.

请确保您的IDE项目设置使用Java JRE 6,而源兼容性设置为1.6或更大。打开窗口> preferences对话框,并浏览到Java>编译器。在那里,你可以在编译器遵从性级别设置为1.6。

Make sure that your IDE projects are setup to use a Java 6 JRE, and that the "source compatibility" is set to 1.6 or greater. Open the Window > Preferences dialog, and browse to Java > Compiler. There you can set the "Compiler compliance level" to 1.6.

记住,Eclipse可以覆盖这些全局设置为特定的项目,所以检查这些了。

Remember that Eclipse can override these global settings for a specific project, so check those too.

更新:

Java 5的下的错误不只是与Eclipse;使用的javac 直接在命令行会给你同样的错误。的这不是有效的Java源5 code。

The error under Java 5 isn't just with Eclipse; using javac directly from the command line will give you the same error. It is not valid Java 5 source code.

不过,您可以指定 -target 1.5 选项JDK 6的的javac ,这将产生一个Java 5版本类文件从Java 6源$ C ​​$ C。

However, you can specify the -target 1.5 option to JDK 6's javac, which will produce a Java 5 version class file from the Java 6 source code.

这篇关于为什么Eclipse的抱怨@Override接口的方法呢?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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