Bug with Override annotations in Eclipse(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
这篇关于Eclipse 中覆盖注释的错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:Eclipse 中覆盖注释的错误
基础教程推荐
- 减少 JVM 暂停时间 >1 秒使用 UseConcMarkSweepGC 2022-01-01
- Java Keytool 导入证书后出错,"keytool error: java.io.FileNotFoundException &拒绝访问" 2022-01-01
- 设置 bean 时出现 Nullpointerexception 2022-01-01
- Java:带有char数组的println给出乱码 2022-01-01
- 降序排序:Java Map 2022-01-01
- “未找到匹配项"使用 matcher 的 group 方法时 2022-01-01
- 在 Libgdx 中处理屏幕的正确方法 2022-01-01
- 如何使用 Java 创建 X509 证书? 2022-01-01
- FirebaseListAdapter 不推送聊天应用程序的单个项目 - Firebase-Ui 3.1 2022-01-01
- 无法使用修饰符“public final"访问 java.util.Ha 2022-01-01