What is the difference between `##` and `hashCode`?

前端 未结 4 1207
陌清茗
陌清茗 2020-11-30 04:53

What is the difference between methods ## and hashCode?

They seem to be outputting the same values no matter which class or hashCode

4条回答
  •  再見小時候
    2020-11-30 05:03

    ## was introduced because hashCode is not consistent with the == operator in Scala. If a == b then a.## == b.## regardless of the type of a and b (if custom hashCode implementations are correct). The same is not true for hashCode as can be seen in the examples given by other posters.

提交回复
热议问题