In Eclipse 3.4.1 using JDK1.6.0_10 how can I activate a warning on a missing @Override
annotation on a method that implements an interface method?
在使用JDK1.6.0_10的Eclipse 3.4.1中,如何在实现接口方法的方法上对缺少的@Override注释激活警告?
In the Preferences window this option:
在“首选项”窗口中,此选项:
Java > Compiler > Errors / Warnings > Annotations > Missing '@Override' annotation
Java>编译器>错误/警告>注释>缺少'@Override'注释
works fine for missing annotations on methods that override a superclass method, but it does nothing for interface methods.
适用于覆盖超类方法的方法上缺少注释,但它对接口方法没有任何作用。
4 个解决方案
#1
10
It is not possible in Eclipse 3.4.1. It is a known issue. See this bug report page for more information.
它在Eclipse 3.4.1中是不可能的。这是一个众所周知的问题。有关更多信息,请参阅此错误报告页面。
#2
2
Belay what I said in the other thread. Apparently it's not a compiler option, but a Java compatibility version issue: if your compatibility version is 5, you won't be able to annotate interface implementation methods. If your compatibility version is 6, then you will be able to.
在另一个帖子中保护我说的话。显然,它不是编译器选项,而是Java兼容版本问题:如果兼容性版本为5,则无法注释接口实现方法。如果您的兼容版本是6,那么您将能够。
However I don't think there's a way of actually forcing Eclipse to generate an error if you do not annotate each implemented method. From this page:
但是,如果不对每个实现的方法进行注释,我认为没有办法实际强制Eclipse生成错误。从这个页面:
Missing '@Override' annotation: When enabled, the compiler will issue an error or a warning whenever it encounters a method overriding another implemented method, and the '@Override' annotation is missing.
缺少'@Override'注释:启用后,只要遇到覆盖另一个已实现方法的方法,编译器就会发出错误或警告,并且缺少'@Override'注释。
#3
1
The compatibility setting to 1.6 instead of 1.5 worked for me on: Eclipse Java EE IDE for Web Developers.
兼容性设置为1.6而不是1.5对我有用:用于Web开发人员的Eclipse Java EE IDE。
Build id: 20100218-1602
构建ID:20100218-1602
#4
0
Maybe I'm missing something but interface methods are already required to be implemented by implementation classes.
也许我错过了一些东西,但是实现类已经需要实现接口方法。
The compiler will generate an error if the interface is not completely implemented.
如果接口未完全实现,编译器将生成错误。
#1
10
It is not possible in Eclipse 3.4.1. It is a known issue. See this bug report page for more information.
它在Eclipse 3.4.1中是不可能的。这是一个众所周知的问题。有关更多信息,请参阅此错误报告页面。
#2
2
Belay what I said in the other thread. Apparently it's not a compiler option, but a Java compatibility version issue: if your compatibility version is 5, you won't be able to annotate interface implementation methods. If your compatibility version is 6, then you will be able to.
在另一个帖子中保护我说的话。显然,它不是编译器选项,而是Java兼容版本问题:如果兼容性版本为5,则无法注释接口实现方法。如果您的兼容版本是6,那么您将能够。
However I don't think there's a way of actually forcing Eclipse to generate an error if you do not annotate each implemented method. From this page:
但是,如果不对每个实现的方法进行注释,我认为没有办法实际强制Eclipse生成错误。从这个页面:
Missing '@Override' annotation: When enabled, the compiler will issue an error or a warning whenever it encounters a method overriding another implemented method, and the '@Override' annotation is missing.
缺少'@Override'注释:启用后,只要遇到覆盖另一个已实现方法的方法,编译器就会发出错误或警告,并且缺少'@Override'注释。
#3
1
The compatibility setting to 1.6 instead of 1.5 worked for me on: Eclipse Java EE IDE for Web Developers.
兼容性设置为1.6而不是1.5对我有用:用于Web开发人员的Eclipse Java EE IDE。
Build id: 20100218-1602
构建ID:20100218-1602
#4
0
Maybe I'm missing something but interface methods are already required to be implemented by implementation classes.
也许我错过了一些东西,但是实现类已经需要实现接口方法。
The compiler will generate an error if the interface is not completely implemented.
如果接口未完全实现,编译器将生成错误。