我有一个现有项目在覆盖 interface 方法而不是超类方法的方法上使用 @Override
.我无法在代码中更改它,但我希望 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.
我将如何禁用此错误?
注意:由于项目需要,我需要为Java 1.5编译.
在实现接口声明的方法的方法上使用 @Override
注释仅从 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 6 JRE,并且源兼容性"设置为 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:
请记住,Eclipse 可以覆盖特定项目的这些全局设置,因此也请检查这些设置.
Remember that Eclipse can override these global settings for a specific project, so check those too.
更新:
Java 5 下的错误不仅仅是 Eclipse;直接从命令行使用 javac
会给你同样的错误.它不是有效的 Java 5 源代码.
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.
但是,您可以为 JDK 6 的 javac
指定 -target 1.5
选项,这将从 Java 6 源代码生成 Java 5 版本的类文件.
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?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!