What is the difference between being shallowly and deeply equal? How is this applied to caching?

后端 未结 5 1795
轻奢々
轻奢々 2020-12-15 12:38

Found the following in my notes, but I am unable to make sense of it:

Primitive type wrapper classes implement caching for a limited number of value

5条回答
  •  遥遥无期
    2020-12-15 13:18

    What you call "shallow equal" is identity: two references (i.e. objects) are identical if they are the very same instances. If you know what pointers are in other languages, you can compare identity to pointer equality.

    What you call "deep equal" is equality: two objects a and b are equal if a.equals(b) returns true (and hopefully vice versa). The correctness of equality strongly depends on the way the equals method is implemented. See the Javadoc of the Object class for more details.

提交回复
热议问题