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

后端 未结 5 1815
轻奢々
轻奢々 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条回答
  •  旧时难觅i
    2020-12-15 13:30

    equals() tests whether two objects are essentially the same, but it can return true for two distinct objects; i.e., two different paper clips are "equals". "==" for reference types tests whether two references refer to the same object -- i.e., a paper clip is == only to itself. == tests identity, which equals tests equivalence.

    You could have two distinct Integer objects with a 0 in them (they are equals()); caching means saving objects and reusing them when possible.

提交回复
热议问题