Scala Tutorial - Scala Type Hierarchy








Unlike Java, there are no primitive types in Scala.

All data types in Scala are objects that have methods to operate on their data.

All Scala's types exist as part of a type hierarchy.

Every class that you define in Scala will also belong to this hierarchy automatically.

Any
 +---AnyVAl
 |     +---Numberic Types
 |     |
 |     +---Char
 |     |
 |     +---Boolean
 |
 +---AnyRef
       +---Collections
       |
       +---Classes
       |     +---Null
       |
       +---String

Any, AnyVal and AnyRef Types

Class Any is the root of the Scala class hierarchy and is an abstract class.

Every class in a Scala inherits directly or indirectly from this class.

AnyVal and AnyRef extend Any type. The Any, AnyVal,and AnyRef types are the root of Scala's type hierarchy.

All other types descend from AnyVal and AnyRef.

The types that extend AnyVal are known as value types.