0
                if (BigDecimal.ZERO == actualSettlementAmountDetail) {

or

                if (BigDecimal.ZERO.equals(actualSettlementAmountDetail)) {

where actualSettlementAmountDetail is a BigDecimal.

BigDecimal actualSettlementAmountDetail;

I am solving code quality issues reported by CAST and the quality rule states that -

Check usage of '==' and '!=' on objects

  • 2
    remember that, whenever you have the opportunity to use `equals` don't think about the `"=="`anymore – Mustapha Belmokhtar Dec 07 '17 at 09:49
  • use the equals method – Maurice Perry Dec 07 '17 at 09:53
  • 1
    Note that in some cases you might want to use `compareTo()` instead of `equals()`: [BigDecimal equals() versus compareTo()](https://stackoverflow.com/q/6787142/2759108) – SharpKnight Dec 07 '17 at 10:00
  • @Maurice: No, use `compareTo()`. `equals()` will also fail if one BigDecimal is BigDecimal.ZERO and the other has a value like .0.000 – Rudy Velthuis Dec 07 '17 at 13:37
  • FWIW, as I said, this is not a duplicate. Equals only returns true if the BigDecimals are exactly equal, i.e. have the same value and scale. CompareTo also returns true if they have a different scale, but othrwise same value, i.e. it compares 0.1 and 0.1000 as equal. So for BigDecimal, things are slightly different and equals() is the wrong method. – Rudy Velthuis Dec 08 '17 at 07:34

0 Answers0