Skip to content

Instantly share code, notes, and snippets.

@gaplo917
Created January 15, 2017 15:19
Show Gist options
  • Save gaplo917/c906c868a5491b8e5d57e3d569e7aeb8 to your computer and use it in GitHub Desktop.
Save gaplo917/c906c868a5491b8e5d57e3d569e7aeb8 to your computer and use it in GitHub Desktop.
Kotlin Functional Support 5 - Every Thing is an expression
// Every Thing is an expression
val input = 1
val result = if(input == 1) "Equal to one" else "Not Equal to One"
val result2 = when(input) {
1 -> "Equal to one"
else -> "Not equal to one"
}
val result3 = try {
input / 0
"Can be calculated"
} catch(e: ArithmeticException){
"Can't be calculated"
}
println(result) // Equal to one
println(result2) // Equal to one
println(result3) // Can't be calculated
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment