问题描述
我在 Eclipse 中遇到 @Override
注释的烦人问题.通常,当我在新 PC 上导入工作项目时,Eclipse 会将某些 @Override
注释标记为错误.如果我删除注释,一切都很好,Eclipse 还表明这些方法正在覆盖父方法,但添加 Override 注释会再次导致错误.我目前正在开发一个 Android 项目,所以它可能是 Android 的问题,而不是 Eclipse 的问题..
这很可能是因为您要在 Java 1.5 和 Java 1.6 之间切换.在 1.5 中,您无法使用 @Override 标记接口实现,但在 1.6 中可以.
在 Google 上的快速搜索中找到了关于两个版本之间此注释差异的很好解释:http://www.techienuggets.com/CommentDetail?tx=38155
@Override 的语义在JDK 1.5 和 JDK 1.6.在 JDK 1.5 中,不允许使用@Override 注释方法的实现在接口中声明,而它们在 JDK 1.6 中是允许的.更多信息,见:
http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=5008260http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=6399361http://blogs.oracle.com/ahe/?entry=override>
事实上,描述覆盖注释未更新在 JDK API 文档中.这已经报告为错误:
http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=6501053bugdatabase/view_bug.do?bug_id=6501053
I have a annoying problem with @Override
annotations in Eclipse. Often when i import working projects on a new PC, Eclipse marks some of the @Override
annotations as wrong. If i remove the annotations everything is fine and Eclipse also indicates that the methods are overriding the parents methods but adding the Override annotation causes the error again. I am currently working on an Android project so it might be a problem with Android and not with Eclipse..
This is most likely because you are switching between Java 1.5 and Java 1.6. In 1.5 you couldn't mark interface implementations with @Override, but you can in 1.6.
A quick Google search turned up this good explanation of the difference in this annotation between the two versions: http://www.techienuggets.com/CommentDetail?tx=38155
这篇关于Eclipse 中带有覆盖注释的错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!