Sonntag, 3. April 2011

scala.Null and scala.Nothing

scala.Null and scala.Nothing

excerpted from : An overview of the Scala Programming Language
page 3

Type Null is the subtype of all reference type; its only instance is the null reference. since Null is not a subtype of value types, null is not a member of any such type. For instance, it is not possible to assign null to a variable of type int.

Type Nothing is a subtype of every other type; there exist no instances of this type. Even though type Nothing is empty, it is nevertheless useful as a type parameter.

eg., the scala library defines a value Nil of type List[Nothing]. Because lists are covariant in Scala, this makes Nil an instance of List[T], for any element type T.

http://www.scala-lang.org/docu/files/ScalaOverview.pdf#



Keine Kommentare: