为什么是@Override注释javac的失败 [英] Why is javac failing on @Override annotation

查看:352
本文介绍了为什么是@Override注释javac的失败的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Eclipse是,当我实现一个接口的方法添加@Override注解。 Eclipse中似乎与这个没有问题。而我们从巡航控制系统自动生成过程似乎与这个没有问题。但是,当我在命令行,用Ant运行javac的建设,我得到这个错误:

Eclipse is adding @Override annotations when I implement methods of an interface. Eclipse seems to have no problem with this. And our automated build process from Cruise Control seems to have no problem with this. But when I build from the command-line, with ant running javac, I get this error:

[javac] C:\path\project\src\com\us\MyClass.java:70: method does not override a method from its superclass
[javac]     @Override
[javac]      ^
[javac] 1 error

Eclipse是Java 1.6的下运行。巡航控制系统正在运行的Java 1.5。不管我使用的Java版本我的Ant生成失败。

Eclipse is running under Java 1.6. Cruise Control is running Java 1.5. My ant build fails regardless of which version of Java I use.

推荐答案

@Override批注规范用Java 1.6的变化。在Java 1.5中,编译器并没有让上实现的接口方法@Override注释,但在1.6它。我发现第一个搜索结果是一个此处的博客文章。。它不是有据可查,但它的确发生了变化。

The @Override annotation spec changed in Java 1.6. In Java 1.5, the compiler did not allow the @Override annotation on implemented interface methods, but in 1.6 it does. First search result I found is a blog post here.. It was not well documented, but it did change.

Eclipse是将它,因为您的E​​clipse设置为1.6符合性...你应该尽量保持你的构建和Eclipse环境会在同一个版本的Java。这是我不清楚你指定巡航控制系统上运行它是否正在使用一个单独的JDK6与否编译Java 5。

Eclipse is adding it because your Eclipse is set for 1.6 compliance...you should try to keep your build and eclipse environments on the same version of Java. It's unclear to me by your specifying Cruise Control is running Java 5 on whether or not it is compiling using a separate JDK6 or not.

从上面的1.5 VS 1.6 @Override注释规则分开的,记住,Eclipse拥有自己的编译器实现(不javac的),并会偶尔有不同的行为。每当编译的东西在Eclipse中,而不是Ant或Maven,你需要找到一种方法,使双方的编译器高兴。

Separate from the above 1.5 vs 1.6 @Override annotation rules, remember that Eclipse has its own compiler implementation (not javac) and will occasionally have different behavior. Whenever something compiles in Eclipse, but not Ant or Maven, you will need to find a way to make both compilers happy.

这篇关于为什么是@Override注释javac的失败的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆