Exhaustive when over enum may now use "is" instead of comparison + a pair of tests

This commit is contained in:
Mikhail Glukhikh
2015-06-29 13:55:08 +03:00
parent 786cadb08b
commit e1d3b296e9
6 changed files with 147 additions and 45 deletions
@@ -0,0 +1,11 @@
enum class MyEnum {
A, B, C
}
fun foo(x: MyEnum): Int {
return when (x) {
MyEnum.A -> 1
is MyEnum.B -> 2
is MyEnum.C -> 3
}
}