Functions and classes

In Scala, every value is an object. Functions are first-class values, which also makes them objects of their respective classes.

The following diagram shows the Scala unified type system and how this is achieved. It is adapted from http://www.scala-lang.org/old/sites/default/files/images/classhierarchy.png and represents an up-to-date view of the model (some classes such as ScalaObject have disappeared, as we have already mentioned earlier):

As you can see, Scala does not have the same concept of primitive types that Java has, and all types are ultimately subtypes of Any.

Get Scala Design Patterns - Second Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.