Created
May 18, 2011 14:21
-
-
Save ReSTARTR/978661 to your computer and use it in GitHub Desktop.
Option型の動作確認
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
// 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