Labels

Monday, April 11, 2022

Scala Hierarchy (Class -25)

In Scala programming language everything is an object. Even data types are treated as objects and have some method that performs operations of the data stored by them.

So, all values have a type, including numerical value, classes and functions. The diagram below illustrates a subset of the type hierarchy.



Any is the parent data type (supertype) of all types, also called the top type. It defines certain universal methods such as equals, hash Code, and toString

Any has two direct subclasses: AnyVal and AnyRef.

A)     AnyVal represents 9 non-null able value types which are : DoubleFloatLongIntShortByteCharUnit, and BooleanUnit is a value type which carries no meaningful information. 

B)      AnyRef represents non-value reference types. Every user-defined type in Scala is a subtype of AnyRef. If Scala is used in the context of a Java runtime environment, AnyRef corresponds to java.lang.Object.

There are two important types that are at the bottom of the hierarchy. They are 

a) Nothing & b) Null.

The type at the bottom of the hierarchy that is a subtype of all the types in Scala is Nothing. There is no value of this type.

Null type is subtype of reference types (for all subtypes of AnyRef type).

No comments:

Post a Comment