Skip to content

Instantly share code, notes, and snippets.

@alexfacciorusso
Created February 17, 2018 00:33
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 alexfacciorusso/bb48d7fd86f6263f625a8d7ac22e2eaa to your computer and use it in GitHub Desktop.
Save alexfacciorusso/bb48d7fd86f6263f625a8d7ac22e2eaa to your computer and use it in GitHub Desktop.
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