3

Are there any utils in java which allow to check objects equality without equals overriding? For some reasons I don't want to provide my class with equals method. I need something like SomeUtils.equals(a,b) in my unit test which compares all object fields (via reflection I guess).

Normal
  • 1,347
  • 4
  • 17
  • 34

1 Answers1

6

You could use EqualsBuilder.reflectionEquals(this, obj); in Apache Commons EqualsBuilder

Syam S
  • 8,421
  • 1
  • 26
  • 36
  • Thanks! That is I'm looking for. As mention by @bhspencer, my question is duplication for http://stackoverflow.com/questions/1449001/is-there-a-java-reflection-utility-to-do-a-deep-comparison-of-two-objects – Normal May 12 '15 at 15:47
  • This does not work. – fuat Sep 13 '21 at 17:58
  • @fuat What does not work about it? – Mark Feb 14 '22 at 12:50