Check out the Scala language specification, namely 6.3 The Null Value chapter:
The null value is of type scala.Null
, and is thus compatible with every reference
type. It denotes a reference value which refers to a special “null” object. This object
implements methods in class scala.AnyRef
as follows:
• eq(x)
and ==(x)
return true if the argument x
is also the “null” object.
• ne(x)
and !=(x)
return true if the argument x
is not also the “null” object.
This means that semantically when you compare something with null
literal or null
literal with something you are actually referring to method of a special scala.Null
class. Treat null
literal as a shorthand for that class.
Of course at the implementation level it is optimized and ordinary null
is used.