Skip to content

Instantly share code, notes, and snippets.

@jboner
Created February 14, 2009 13:55
Show Gist options
  • Save jboner/64367 to your computer and use it in GitHub Desktop.
Save jboner/64367 to your computer and use it in GitHub Desktop.
Nullify: dealing with null in Scala
scala> def nullify[T >: Null <: AnyRef](x : Option[T]) = x getOrElse null
nullify: [T >: Null <: AnyRef](Option[T])T
scala> val result1 : Option[String] = Some("hello")
result1: Option[String] = Some(hello)
scala> val result2 : Option[String] = None
result2: Option[String] = None
scala> nullify(result1)
res0: String = hello
scala> nullify(result2)
res1: String = null
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment