What is the difference between ==
and .equals()
in Scala, and when to use which?
Is the implementation the same as in Java?
There is a similar question (Why == operator and equals() behave differently for values of AnyVal in Scala), but that is specific to AnyVal
. This question is concerned with the more general case of Any
.
You normally use ==
, it routes to equals
, except that it treats null
s properly. Reference equality (rarely used) is eq
.