Created
February 17, 2018 00:33
-
-
Save alexfacciorusso/bb48d7fd86f6263f625a8d7ac22e2eaa to your computer and use it in GitHub Desktop.
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
class Cat { | |
val meow = "Meowww...? :3" | |
} | |
fun main(args: Array<String>) { | |
var aBoringClassInstance: Cat? = Cat() | |
aBoringClassInstance!! | |
val sureNull: Cat? = null | |
sureNull!! | |
// oops! NPE :/ | |
val maybeACat = openBox() | |
val meow = maybeACat?.meow!! | |
// NPE...? | |
} | |
fun openBox(): Cat? { | |
return if (Random().nextInt(2) == 0) Cat() | |
else null | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment