Skip to content

Instantly share code, notes, and snippets.

@jacobmoncur
Created January 15, 2016 05:04
Show Gist options
  • Save jacobmoncur/b124d4b401d3ebaf538b to your computer and use it in GitHub Desktop.
Save jacobmoncur/b124d4b401d3ebaf538b to your computer and use it in GitHub Desktop.

Nullable

// Optional listener
listenerInterface?.notifyOfSomething()


// `elvis operator` ?: allows for default value
val likeCount = comment?.likes ?: 0


// Smart Cast
if(user != null) {
    user.foo() // compiler knows user isn't null, `?` isn't needed
} else {

}

// if-let
user?.let {
    it.foo()
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment