我可以让 Java 5 忽略 @Override 错误吗?
可能的重复:
为什么 Eclipse 会抱怨接口方法上的 @Override?
我有一些使用 Eclipse 和 Java 6 SDK 编写的 Java 代码,因此实现接口的方法使用 @Override
进行注释 - 该注释在 Java 6 中合法,但在 Java 5 中不合法 。
我想使用 Java 5 SDK(Mac OS X 10.5 上的 javac
)编译相同的代码 除了 @Override 注释之外,一切都可以正常编译和运行。有什么方法可以让 javac 忽略该项目的 @Override 注释,或者是删除所有注释的唯一解决方案?
Possible Duplicate:
Why does Eclipse complain about @Override on interface methods?
I have some Java code that was written using Eclipse and the Java 6 SDK, so methods that implement an interface are annotated with @Override
- an annotation that is legal in Java 6, but not in Java 5.
I'd like to compile the same code using the Java 5 SDK (javac
on Mac OS X 10.5). Everything compiles and runs fine except for the @Override
annotations. Is there any way I can get javac to ignore the @Override
annotations for this project, or is the only solution to remove them all?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
不幸的是,唯一的方法是实际删除注释。
如果您确实希望使用 Java 5 编译和运行代码,则应该针对 Java 5 进行开发。否则,您可能会意外依赖 Java 6 特定的 SDK 方法等。
Unfortunately, the only way is to actually remove the annotations.
If you do want to have your code compile and run with Java 5, you should develop targeting Java 5. Otherwise, you might accidentally rely on a Java 6 specific SDK methods and such.
显然你可以升级到Java 1.5 u21,这将解决问题:
Why is javac @Override 注释失败
Apparently you can upgrade to Java 1.5 u21 and this will fix the problem:
Why is javac failing on @Override annotation
您可以使用JDK6来编译1.5代码。使用
-bootclasspath
、-target
和-source
。或者,我相信 Eclipse 编译器会同样对待@Override
(这可能是错误的!)。1.5已经结束了它的使用寿命,我建议让它腐烂。
You can use JDK6 to compile 1.5 code. Use
-bootclasspath
,-target
, and-source
. Alternatively, I believe the Eclipse compiler treats@Override
the same (this might be wrong!).1.5 has finished its End of Service Life period, and I suggest letting it rot.
@Override 在 java 5 中有效 -> http://java. sun.com/j2se/1.5.0/docs/api/index.html?java/lang/Override.html
我建议您在 Eclipse 中检查项目的编译器设置,也许在 Project ->;编译器->错误/警告 ->注释?
@Override is valid in java 5 -> http://java.sun.com/j2se/1.5.0/docs/api/index.html?java/lang/Override.html
I recommend that you check your project's compiler settings in Eclipse, perhaps at Project -> Compiler -> Error/Warnings -> Annotations?
Java 6 可用于 OS X。检查软件更新。当你有了它之后,将其设置为默认的java版本,然后编译。
Java 6 is available for OS X. Check software update. When you have it, set it to be the default java version, and then compile.