Equality between 2 HashMap

后端 未结 4 2180
醉话见心
醉话见心 2020-12-15 17:33

In the equals() method of my class, I am using a private instance HashMap variable to compare for the equality. However, 2 different objects still show being equal when comp

4条回答
  •  刺人心
    刺人心 (楼主)
    2020-12-15 18:23

    Java's arrays cannot be tested for equality without writing a customized code

    This is just a complicated way of saying that Java arrays do not override Object.equals(). Hence if you compare them using equals() (which is what the equals methods of all the collection classes do), you get "instance equality", instead of "value equality".

    That's really just a special case of the different ways equals works depending on whether it has been overridden or not.

提交回复
热议问题