Created
August 21, 2011 05:42
-
-
Save sidharthkuruvila/1160196 to your computer and use it in GitHub Desktop.
Wrap method calls that return null in Option
This file contains hidden or 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
| def canReturnNull() = "hello world" | |
| println(Option(canReturnNull) getOrElse "I'm saying nothing") | |
| //Prints: hello world | |
| def canReturnNull() = null | |
| println(Option(canReturnNull) getOrElse "I'm saying nothing") | |
| //Prints: I'm saying nothing |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment