使Eclipse等于()/ hashCode()使用getter [英] make Eclipse equals() / hashCode() use getters

查看:244
本文介绍了使Eclipse等于()/ hashCode()使用getter的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否可以使用默认的Eclipse生成hashCode()和equals()使用getter而不是字段引用? - 即我可以使用它使用的模板吗?

Is it possible to make the default Eclipse "Generate hashCode() and equals()" use getters instead of field references? - ie. can I get at the template that it uses?

我正在使用Hibernate,而在使用getter而不是从字段引用时,Proxied Objects只是LazyLoaded。

I'm using Hibernate, and Proxied Objects are only LazyLoaded when getters are used and not from field references. It's an annoyance to be constantly changing it.

明显的解决方法是自己创建一个模板,或者编写一个插件 - 这样就像一个过分的。

The obvious workarounds are to create a template myself or write a plugin - which feels like overkill.

编辑:看起来这些不可配置。我会将其作为JBoss工具组的一个问题(他们为Hibernate做了一些插件)。

Looks like these aren't configurable. I'll pose this as a question for the JBoss Tools Group (They make some plugins for Hibernate).

推荐答案

这不是一个解决方案,而不是解决方法 - 但是您可能会尝试生成 equals(),然后使用封装字段重构来替换所有字段acceses以使用getter / setters(它在类内也可以)。

It's not a solution, rather workaround - but you might try generate equals(), then use 'encapsulate field' refactoring to replace all field acceses to use getters/setters (it works inside class also).

这篇关于使Eclipse等于()/ hashCode()使用getter的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆