android - Eclipse 中覆盖注释的错误

标签 android eclipse annotations overriding

Eclipse 中的 @Override 注释有一个烦人的问题。通常,当我在新 PC 上导入工作项目时,Eclipse 会将一些 @Override 注释标记为错误。如果我删除注释一切都很好,Eclipse 还表明这些方法正在覆盖父方法,但添加 Override 注释会再次导致错误。我目前正在开发一个 Android 项目,所以它可能是 Android 的问题,而不是 Eclipse 的问题。

最佳答案

这很可能是因为您在 Java 1.5 和 Java 1.6 之间切换。在 1.5 中,您无法使用 @Override 标记接口(interface)实现,但在 1.6 中可以。

通过 Google 快速搜索,可以很好地解释两个版本之间此注释的差异: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

关于android - Eclipse 中覆盖注释的错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3735661/

相关文章:

java - 我如何在 ArrayAdapter 类的 getView 方法中使用 startActivityForResult?

android - 如何检测Android应用程序中的慢速互联网连接

android - 尽管添加了 android : exported flag,但在迁移到 android 12 时 <receiver> 的 list 合并失败

python - 如何在悬停时注释broken_barh图表?

java - 使用 GPS 创建 Android 位置 API 时,mLastLocation 值变为 null

eclipse - HTTP 状态 [404] ? [Not Found](源站没有找到当前表示)

java - 关于 EAR 与 WAR 的 EJB 解释

ios - 如何在 iPhone 中使用图像和标签在 Mapview 中添加注释?

javascript - 如何在 dygraph 中添加注释?

android - 静态最终变量在 Debug模式下显示为 null 和 0.0