Check objects equality without equals overriding i

2019-02-26 22:54发布

问题:

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

回答1:

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