0
scala> val x:String = null
x: String = null

scala> x == "Hey"
res0: Boolean = false

This should translate to x.equals("Hey")?

Dragonborn
  • 1,755
  • 1
  • 16
  • 37
  • 4
    Because `==` is not equal to `equals`, see: http://stackoverflow.com/questions/7681161/whats-the-difference-between-and-equals-in-scala – kiritsuku Nov 09 '15 at 15:25

1 Answers1

3

As per the SLS:

6.3 The Null Value

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 iff the argument x is also the “null” object.

• ne(x ) and !=(x ) return true iff the argument x is not also the “null” object.

• isInstanceOf[T ] always returns false.

• asInstanceOf[T ] returns the default value (see §4.2) of type T .

• ## returns “0”. A reference to any other member of the “null” object causes a NullPointerException to be thrown.

tkroman
  • 4,811
  • 1
  • 26
  • 46