Scala reference equality

后端 未结 1 776
醉酒成梦
醉酒成梦 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)
提交回复
热议问题