Scala reference equality

后端 未结 1 1515
死守一世寂寞
死守一世寂寞 2021-02-11 12:42

How do you test reference equality in Scala?

val x = new Obj
val y = x
x.referenceEquals(y) // evaluates to true
相关标签:
1条回答
  • 2021-02-11 13:11

    The function you are looking for is eq, which is a member of AnyRef:

    val x = new Obj
    val y = x
    x eq y // evaluates to true
    x ne y // evaluates to false
    
    0 讨论(0)
提交回复
热议问题