Add warning for missing @Override annotation for interface implementation in Eclipse

心不动则不痛 提交于 2019-12-03 09:23:09

问题


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?

In the Preferences window this option:

Java > Compiler > Errors / Warnings > Annotations > Missing '@Override' annotation

works fine for missing annotations on methods that override a superclass method, but it does nothing for interface methods.


回答1:


It is not possible in Eclipse 3.4.1. It is a known issue. See this bug report page for more information.




回答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.

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:

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.




回答3:


The compatibility setting to 1.6 instead of 1.5 worked for me on: Eclipse Java EE IDE for Web Developers.

Build id: 20100218-1602




回答4:


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.



来源:https://stackoverflow.com/questions/224945/add-warning-for-missing-override-annotation-for-interface-implementation-in-ecl

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!