Hi all, very general Kotlin question here. Is there a way to access a property of a context object when using when clause? For example let's say I have someObj reference which has a string property of propOfSomeObj.
when (someObj) {
::propOfSomeObj.isBlank() -> ...
}
🚫 1
Twferrell
04/28/2020, 3:01 PM
@Ruckus, gotcha. Thanks very much for your reply. Really appreciate it!
s
Sam Garfinkel
04/29/2020, 4:19 AM
Actually you sort of can. You can assign the context to a val. This is valid:
Copy code
when(val it = someObj) {
it.propOfSomeObj.isBlank() ->
}
However it does add some verbosity. I agree it would be nice for the context to be bound to some default name
Sam Garfinkel
04/29/2020, 6:39 AM
Oh crap, yeah, you’re right. I should not code after midnight 😉