Scala reference equality

Scala

Scala Problem Overview


How do you test reference equality in Scala?

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

Scala Solutions


Solution 1 - Scala

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

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionLandon KuhnView Question on Stackoverflow
Solution 1 - ScalaJAiroView Answer on Stackoverflow