Created
January 15, 2017 15:19
-
-
Save gaplo917/c906c868a5491b8e5d57e3d569e7aeb8 to your computer and use it in GitHub Desktop.
Kotlin Functional Support 5 - Every Thing is an expression
This file contains hidden or 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
// 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