Skip to content

Instantly share code, notes, and snippets.

@ReSTARTR
Created May 18, 2011 14:21
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ReSTARTR/978661 to your computer and use it in GitHub Desktop.
Save ReSTARTR/978661 to your computer and use it in GitHub Desktop.
Option型の動作確認
// execute in REPL
def testA(x:Boolean):Option[String] = if (x) Some("hoge") else None
testA(true) // Option[String] = Some(hoge)
testA(false) // Option[String] = None
testA(false).getOrElse("moge") // String = moge
testA(false).getOrElse(false) // Any = false
val result = testA(false).getOrElse("moge") // String = moge
val result = testA(false).getOrElse(false) // Any = false
val result:String = testA(false).getOrElse(false) // compile error
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment