Equals operator for zeros (BigDecimal / Double) in Java

后端 未结 7 1138
别那么骄傲
别那么骄傲 2020-12-14 06:31

A few interesting observations w.r.t equals operator on 0 and 0.0

  1. new Double(0.0).equals(0) returns false, while new Double(0.0).equals(0

相关标签:
7条回答
  • 2020-12-14 06:55

    new Double(0.0).equals(0) is actually boxed as something like this:

    new Double(0.0).equals(Integer.valueOf(0))
    

    Double.equals(...) will never return true unless given another Double instance.

    0 讨论(0)
提交回复
热议问题