Created
February 14, 2009 13:55
-
-
Save jboner/64367 to your computer and use it in GitHub Desktop.
Nullify: dealing with null in Scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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