C # Nullable type means that value types are null and Scala Option means getting rid of null . Instead, you draw a match on Option[A] to get Some or None . You can think of Option as a generic version of the Nullable type .
However, the problems are not exactly the same: C # is trying to add object type behavior to value types, while Scala is trying to provide a safe alternative to null . However, Scala Option also sorts the Nullable type value type problem, designed for:
scala> case class MyInt(val i: Int) extends AnyVal // scala value type scala> null : MyInt <console>:14: error: type mismatch; found : Null(null) required: MyInt null : MyInt ^ scala> None : Option[MyInt] res1: Option[MyInt] = None scala> Some(MyInt(1)) : Option[MyInt] res2: Option[MyInt] = Some(MyInt(1))
It should also be mentioned that the Nullable type is built into the C # language, and Option is a regular Scala class in the standard library.
source share