how to generically compare entire java beans?

后端 未结 4 947
遥遥无期
遥遥无期 2020-12-02 01:58

I\'ve been trying to grok the org.apache.commons.beanutils library for a method/idiom to evaluate for equality all properties between 2 instances i.e. a generic equ

4条回答
  •  心在旅途
    2020-12-02 02:28

    Or, although not a direct answer to your question, but it might be an answer to your problem (i.e. remove the effort of doing boilerplate code while being super fast)

    if you use Eclipse, the following steps will auto generate the hashCode and equals for you:

    Source > Generate hashCode and equals...

    and then select the fields, it's super effective! :D

    Cheers and I hope it helps whoever comes here with the purpose of cutting some time writing boilerplate.

    PS: I'm sure other popular IDEs must have similar features.

提交回复
热议问题