Last active
October 11, 2018 11:56
-
-
Save elizarov/c283faf16bb3ec011a6366fd32a9e624 to your computer and use it in GitHub Desktop.
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
class Person(val isClever: Boolean) | |
val p = Person(isClever = true) | |
// ERROR - missed "false" | |
val example1 = when (p.isClever) { | |
true -> "Yes, this person is clever" | |
} | |
// No error - all cases matched | |
val example2 = when (p.isClever) { | |
true -> "Yes, this person is clever" | |
false -> "Fully matched!" | |
} | |
// ERROR - even though all cases are "theoretically" matched | |
// replace "number <= 10" with "else" to get it to compile | |
val example3 = run { | |
val number = 10 | |
when (p.isClever) { | |
true -> "Yes, this person is clever" | |
// here is how you structure it | |
false -> when { | |
number > 10 -> "Clever when number is more than 10" | |
number <= 10 -> "Clever when number is not more than 10" | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment