如何防止 Eclipse 添加“最终”?对于某些 Java 代码行?
例如,GWT 2.4.0 仍然抱怨“字段‘private final...’不会被序列化,因为它是最终的”。
最简单的方法是添加一个 setter(或任何虚拟方法,对局部变量进行赋值,我们希望防止它成为最终的(例如,如果 setter 已经有但没有分配))。
For example, GWT 2.4.0 still complains "Field 'private final...' will not be serialized because it is final".
The easiest way is to add a setter (or any dummy-method, making the assignment of local variable, which we want to prevent becoming final (if, for instance, setter already have and it does not assign)).
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以在
Window > 下找到设置。首选项>爪哇>编辑>保存操作>附加操作>配置...>>代码风格
关于您的评论:
Eclipse 确实没有一个干净的方法来做到这一点。您可以做的只是使用 Eclipse 文本编辑器而不是 Java 编辑器打开文件,然后手动删除
final
关键字,但恐怕您无能为力做更多的事情。或者创建一个未使用的方法来重新分配字段,但这也有点hacky。
You can find the settings under
Window > Preferences > Java > Editor > Save Actions > Additional Actions > Configure... > Code Style
And regarding your comment:
Eclipse doesn't really have a clean way to do this. What you could do is just open the file with the Eclipse Text Editor instead of the Java Editor and delete the
final
keyword manually, but I'm afraid there's not much you can do beyond that.Or create an unused method that re-assigns the field, but that's kind of hacky as well.