为什么Eclipse不在“生成委托方法”中添加@Override注解重构?
在 Eclipse 中,如果我尝试将“生成委托方法”重构应用到 Java 类,如下所示:
class Foo implements Bar {
Bar bar;
}
Eclipse 不会为生成的方法生成 @Override
注释。这是一个错误还是有充分的理由?
In Eclipse, if I try to apply a "Generate Delegate Methods" refactoring to a Java class like the following:
class Foo implements Bar {
Bar bar;
}
Eclipse doesn't generate @Override
annotations for the generated methods. Is this a bug or is there a good reason for this?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
这并不能回答您的问题,即为什么在生成委托方法时不添加
@Override
注释,但您可以添加一个保存操作来在保存文件时为您执行此操作。转到注意
Additional actions< 中的
@Override
条目/代码> 部分。如果您缺少这些,请单击配置...
按钮并选择缺少代码
选项卡,然后选择以下选项:如果要将注释添加到整个项目或包中
批量,选择项目或包(或多个),右键单击,然后
选择来源>清理...
在“清理”对话框中,您可以配置自定义配置文件,其中包括
添加缺失的注释。
This doesn't answer your question of why it doesn't add the
@Override
annotation when you generate delegate methods, but you can add a save action to do it for you upon saving the file. Go toNotice the entries for
@Override
in theAdditional actions
section. If those are missing for you, click theConfigure...
button and select theMissing Code
tab and select those options:If you want to add the annotations to an entire project or package in
bulk, select the project or package (or multiples), right-click, and
choose Source > Clean up...
In the Clean Up dialog, you can configure a custom profile that includes
adding missing annotations.
没有充分的理由,但本身并不是“错误”;只是一个缺点。重构可能只是比 @Override 更老——当然,通常比注释更老——并且从未更新过。
No good reason, but not a "bug", per se; just a shortcoming. Probably the refactoring is just older than
@Override
-- older than annotations in general, of course -- and has never been updated.有时在窗口中设置->首选项-> Java->编辑->保存操作会导致不良影响,尤其是在开发 Android 应用程序时对 XML 文件(曾经经历过这种情况)。恕我直言,更好的解决方案是使用 +1 或右键单击包(或类等...),然后选择 Source ->清理以添加所有缺少的 @Override 注释。
Sometimes settings in Window -> Preferences -> Java -> Editor -> Save Actions cause undesired effects especially on XML files while developing Android applications (been there, experienced that). IMHO better solution is to use +1 or right click on package (or class etc...) and then choose Source -> Clean up to add all of your missing @Override annotations.