Alex Rivera | Logout

What's the difference between == and .equals in Scala?

Asked 2011-10-06T22:23:46.577
171

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.

Edit
Report

1 Answer

226

You normally use ==, it routes to equals, except that it treats nulls properly. Reference equality (rarely used) is eq.

answered 2011-10-06T22:33:15.547

Your Answer