Scala 引用相等

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/6835578/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-22 03:16:22  来源:igfitidea点击:

Scala reference equality

scala

提问by Landon Kuhn

How do you test reference equality in Scala?

你如何在 Scala 中测试引用相等性?

val x = new Obj
val y = x
x.referenceEquals(y) // evaluates to true

回答by JAiro

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

您要查找的函数是eq,它是AnyRef的成员:

val x = new Obj
val y = x
x eq y // evaluates to true
x ne y // evaluates to false