I heard someone said:
"Scala uses a type lattice rather than a type hierarchy, which is different from Java".
I do not quite understand what the meaning type lattice is and what the main difference between type lattice and type hierarchy is.
Could someone explain this term to me?
AnyRef represents reference types. All non-value types are defined as 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.
Any has two direct subclasses: AnyVal. AnyRef.
Scala also defines some interesting classes at the bottom of the hierarchy, Null and Nothing, which essentially act as common subclasses. For example, just as Any is a superclass of every other class, Nothing is a subclass of every other class.
Its essentially means that : The type hierarchy for Scala is a lattice, i.e. it has a “bottom” as well as a “top”.
As seen from the image the top type here is Any
and the bottom is Nothing
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With