Skip to content

Instantly share code, notes, and snippets.

@gorrotowi
Created July 26, 2018 00:25
Show Gist options
  • Save gorrotowi/4027e584c916b50203480a449a964223 to your computer and use it in GitHub Desktop.
Save gorrotowi/4027e584c916b50203480a449a964223 to your computer and use it in GitHub Desktop.
Use elvis operator instead if/else
val name:String? = null
val l:Int = name?.length ?: -1
print(l) // -1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment