当我实现接口的方法时,Eclipse 正在添加 @Override 注释.Eclipse 似乎对此没有任何问题.而我们来自 Cruise Control 的自动化构建过程似乎对此没有任何问题.但是当我从命令行构建时,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:pathprojectsrccomusMyClass.java:70: method does not override a method from its superclass
[javac] @Override
[javac] ^
[javac] 1 error
Eclipse 在 Java 1.6 下运行.Cruise Control 正在运行 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 正在添加它,因为您的 Eclipse 设置为符合 1.6.您应该尝试将您的构建和 Eclipse 环境保持在相同版本的 Java 上.我不清楚您指定 Cruise Control 是否正在运行 Java 5 是否使用单独的 JDK6 进行编译.
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.
这篇关于为什么javac在@Override注释上失败的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!