Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why does `ScalaObject` exist?

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?

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)?

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

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

like image 865
soc Avatar asked Sep 25 '10 20:09

soc


1 Answers

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.

like image 75
Fred Foo Avatar answered Sep 23 '22 02:09

Fred Foo