kotlin-when Questions
2
Non exhaustive when statements on sealed class/interface will be prohibited in Kotlin 1.7.
I have a sealed class State and it's children:
sealed class State {
object Initializing : State()
object...
Acronym asked 25/5, 2022 at 15:0
5
Solved
Is there any way to cast a when argument to an enum?
enum class PaymentStatus(val value: Int) {
PAID(1),
UNPAID(2)
}
fun f(x: Int) {
val foo = when (x) {
PaymentStatus.PAID -> "PAID"
P...
Downing asked 23/1, 2019 at 21:38
2
Solved
As per documentation of When in Kotlin, else is not mandatory if the compiler knows all the values are covered. This is very in case of emums or sealed class but how to do it in case of arrays for ...
Vivianaviviane asked 4/8, 2020 at 8:25
2
Solved
Currently I have a when block like this:
val foo = getStringFromBar()
when {
foo == "SOMETHING" -> { /*do stuff*/ }
foo == "SOMETHING ELSE" -> { /*do other stuff*/ }
f...
Ginelle asked 25/9, 2019 at 7:3
1
© 2022 - 2024 — McMap. All rights reserved.