BigDecimal has a wonky definition of equality, for example 1E2 is not equal to 100 in the sense that bigDecimalA.equals(bigDecimalB) would return false because they have different scales. Whilst we defer to BD's authors - that is evidently how they intend for equality to work - it's confusing in any case (not our fault), and often folks want to define equality as: Does it represent the same value?
There IS a way to accomplish this:
@EqualsAndHashCode.Include
private BigDecimal nameOfBigDecimalField() {
return nameOfBigDecimalField..stripTrailingZeros();
}
This should be named on the feature page of @EqualsAndHashCode; probably in the smallprint, and including that snippet or at least a link to it.
See issue #1260 where @wacker confirmed that this 'trick' works.
BigDecimal has a wonky definition of equality, for example
1E2is not equal to100in the sense thatbigDecimalA.equals(bigDecimalB)would returnfalsebecause they have different scales. Whilst we defer to BD's authors - that is evidently how they intend for equality to work - it's confusing in any case (not our fault), and often folks want to define equality as: Does it represent the same value?There IS a way to accomplish this:
This should be named on the feature page of
@EqualsAndHashCode; probably in the smallprint, and including that snippet or at least a link to it.See issue #1260 where @wacker confirmed that this 'trick' works.