为什么存在`ScalaObject`? [英] Why does `ScalaObject` exist?

查看:97
本文介绍了为什么存在`ScalaObject`?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

为什么所有Scala类都继承自 ScalaObject ,尽管该特征完全为空且与 AnyRef ,它确实定义了其他方法?

Why do all Scala classes inherit from ScalaObject although that trait is completely empty and has no (visible?) functionality compared to AnyRef, which does define additional methods?

这不会减慢方法调用,如 equals() hashCode()因为它需要考虑另一个类(可能会覆盖这些方法)?

Won't that slow down method calls like equals() or hashCode() because it will need to take another class into consideration (which might override the methods)?

是不是可以将AnyRef和ScalaObject折叠成一个类?

Isn't it possible to fold AnyRef and ScalaObject into one class?

更新:
ScalaObject 已使用新的2.10版Scala进行了根除。

UPDATE: ScalaObject was eradicated with new 2.10 version of Scala.

推荐答案

ScalaObject 插入一个 $ tag 方法,根据 2.7的库源代码,用于优化匹配案例类构造函数的模式匹配表达式。由于名称以 $ 开头,因此它当然应被视为应用程序员隐藏。在Scala 2.8中,它完全是空的,所以我猜它是为了向后兼容。

ScalaObject inserts a $tag method, which, according to the comment in the library source code for 2.7, "is needed for optimizing pattern matching expressions which match on constructors of case classes." Since the name starts with $, it should of course be considered "hidden" to application programmers. In Scala 2.8, it's entirely empty, so I guess it's there for backward compatibility.

这篇关于为什么存在`ScalaObject`?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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