Is there a way to reference the value being checke...
# announcements
d
Is there a way to reference the value being checked in a when statement? I could obviously store the value locally, just trying to be succinct.
Copy code
when (someCalculatedValue()) {
   1 -> doSomething(/*use value here*/)
   else -> log("nothing")
}
m
dblack:
doSomething(1)
😉
d
Bleeeeet. Happy Monday 😆 More readable that way.
I want to log in the else statement though (my example was bad)
Basically... hey, you shouldn't have gotten to the else statement, but we'll log the value that got you here anyways.
m
I suspected that.
Just
val value = call()
then
when (value) {
, but you know that.
It's weird how people try to bend the language instead of using the simplest constructs. Good example is
variable?.let { }
with
else
if value is null.