Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why's type lattice in Scala?

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?

like image 449
CSnerd Avatar asked Dec 11 '14 16:12

CSnerd


People also ask

What is AnyRef in Scala?

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.

Which is a subclass of all classes Scala?

Any has two direct subclasses: AnyVal. AnyRef.

Which class is the super class of all classes in Scala?

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.


Video Answer


1 Answers

Its essentially means that : The type hierarchy for Scala is a lattice, i.e. it has a “bottom” as well as a “top”.

enter image description here

As seen from the image the top type here is Any and the bottom is Nothing.

like image 197
nitishagar Avatar answered Sep 17 '22 17:09

nitishagar