Hi all, very general Kotlin question here. Is the...
# announcements
t
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
r
Unfortunately not, though there is a long standing issue to add arbitrary lambdas to
when
clauses.
t
@Ruckus, gotcha. Thanks very much for your reply. Really appreciate it!
👍 1
s
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
r
That doesn't work, as it's not using the result of
isBlank
, but instead comparing it to
someObj
.
s
Oh crap, yeah, you’re right. I should not code after midnight 😉
😆 1