Matej Kormuth
02/03/2019, 12:06 AMit
or similar variable in else
clause of when
control structure.
when (a()) {
1 -> b()
2 -> c()
else -> d(it)
}
Ruckus
02/03/2019, 12:19 AMwhen (val res = a()) {
...
else -> d(res)
}
The advantage of this as opposed to assigning a val before the when is that res
is confined to the scope of the when.Marc Knaup
02/03/2019, 5:00 AMit
would also break existing code where when
together with it
is used in a lambda.
btw it's not just a problem with else
but also the other branches. You don't have the value in the right type there unless you use the preferred approach Ruckus has mentioned.xenoterracide
02/04/2019, 4:24 PMbenleggiero
02/05/2019, 2:28 AM