how to generically compare entire java beans?

ysouter picture ysouter · Jan 23, 2009 · Viewed 21.1k times · Source

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 equals() method for beans.
Is there a simple way to do this usnig this library? Or am I going about this the wrong way? Thanks.

Answer

Aaron Digulla picture Aaron Digulla · Jan 23, 2009

Try EqualsBuilder.reflectionEquals() of commons-lang. EqualsBuilder has a set of methods to include all fields, all non-transient fields and all but certain fields.

If all else fails, the code could serve as a good example how to implement this.