fun foo(amount: Int) {
when (amount) {
in Int.MIN_VALUE..0 -> doStuff1()
in 1..9 -> doStuff2()
in 10..Int.MAX_VALUE -> doStuff3()
}
}
When I do this, compiler says that I need an else branch:
fun foo(amount: Int): Int {
return when (amount) {
in Int.MIN_VALUE..0 -> doStuff1()
in 1..9 -> doStuff2()
in 10..Int.MAX_VALUE -> doStuff3()
}
}
so it only let’s me further if I do this, which doesn’t look nice:
fun foo(amount: Int): Int {
return when (amount) {
in Int.MIN_VALUE..0 -> doStuff1()
in 1..9 -> doStuff2()
in 10..Int.MAX_VALUE -> doStuff3()
else -> { -1 } //which will never be called, or?
}
}
Thanks a lot. The basic problem (at least why I consider it as a problem) is having an else, but sure this can work Is there a site where we can check the Kotlin backlog and even further do you know if it’s in the backlog at all?
Their backlog is all on Youtrack
I think it’s not currently a goal. I think Roman once said (but I’m not sure) that it’s currently not a goal for Kotlin since it’ll hit compiler performance and won’t add much usefulness.