Why doesn't Array's == function return true for Array(1,2) == Array(1,2)?

后端 未结 3 1240
名媛妹妹
名媛妹妹 2020-11-30 13:24

In Programming in Scala the authors write that Scala\'s == function compares value equality instead of reference equality.

This works as expected on lis

3条回答
  •  离开以前
    2020-11-30 14:02

    It's all about referential transparency. The idea is, if two values are ==, it shouldn't matter which one you use for something. If you have two arrays with the same contents, it clearly matters which one you modify, so == returns false unless they are the same one.

提交回复
热议问题