Eclipse 中覆盖注释的错误
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=overridep>
事实上,描述覆盖注释未更新在 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
Semantics of @Override is different in JDK 1.5 and JDK 1.6. In JDK 1.5, the @Override annotation is not allowed for implementations of methods declared in an interface, while they are allowed in JDK 1.6. For more information, see:
http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=5008260 http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=6399361 http://blogs.oracle.com/ahe/?entry=override
It is fact that the description of the Override annotation was not updated in the JDK API docs. This has been reported as a bug:
http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=6501053bugdatabase/view_bug.do?bug_id=6501053
相关文章