Scala reference equality

后端 未结 1 775
醉酒成梦
醉酒成梦 2021-02-11 12:34

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:03

    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)
提交回复
热议问题