Scala 中的 == 和 .equals 有什么区别? [英] What's the difference between == and .equals in Scala?
本文介绍了Scala 中的 == 和 .equals 有什么区别?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
==
和 .equals()
在 Scala 中有什么区别,什么时候使用哪个?
What is the difference between ==
and .equals()
in Scala, and when to use which?
实现和Java一样吗?
Is the implementation same as in Java?
相关问题讨论了 AnyVal
的具体情况.更一般的情况是Any
.
The related question talks about specific cases of AnyVal
. The more general case is Any
.
推荐答案
你通常使用 ==
,它路由到 equals
,除了它处理 null
正确.引用相等(很少使用)是 eq
.
You normally use ==
, it routes to equals
, except that it treats null
s properly. Reference equality (rarely used) is eq
.
这篇关于Scala 中的 == 和 .equals 有什么区别?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文