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 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.