Scala中==和.equals有什么区别? [英] What's the difference between == and .equals in Scala?

查看:198
本文介绍了Scala中==和.equals有什么区别?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Scala中的==.equals()有什么区别,什么时候使用?

实现与Java中的实现相同吗?

相关问题讨论AnyVal的具体情况.更一般的情况是Any.

解决方案

您通常使用==,它会路由到equals,但会正确处理null.参考等式(很少使用)为eq.

What is the difference between == and .equals() in Scala, and when to use which?

Is the implementation same as in Java?

EDIT: The related question talks about specific cases of AnyVal. The more general case is Any.

解决方案

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

这篇关于Scala中==和.equals有什么区别?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆