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/