Fundamental Types

Even though you can use any Java type in Scala, you can also enjoy a few types native to Scala. Scala makes a clearer distinction between value types and reference types and also goes a few extra miles with type definitions to enhance type verification and inference. Let’s get a grasp of these fundamental types since you’ll encounter these types in Scala quite often.

The Any Type

Scala’s Any type is a superclass of all types, as you can see here.

images/UsingTypeInference/scalatypes.png

Any can serve as a common reference to objects of any type. Any is an abstract class with the following methods: !=, ==, asInstanceOf, equals, hashCode, isInstanceOf, and toString.

Get Pragmatic Scala now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.