Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

make Eclipse equals() / hashCode() use getters

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?

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.

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

like image 210
Damo Avatar asked Apr 29 '09 15:04

Damo


People also ask

What is contract between hashCode() and equals() method?

If two objects are equal(according to equals() method) then the hashCode() method should return the same integer value for both the objects. But, it is not necessary that the hashCode() method will return the distinct result for the objects that are not equal (according to equals() method).

Why to override equals object and hashCode() method?

Case 1: Overriding both equals(Object) and hashCode() method Whenever it(hashcode) is invoked on the same object more than once during an execution of a Java application, the hashCode method must consistently return the same integer, provided no information used in equals comparisons on the object is modified.


1 Answers

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).

like image 193
jb. Avatar answered Oct 04 '22 18:10

jb.