Is there a way to get sealed class smart casting t...
# announcements
w
Is there a way to get sealed class smart casting to work when filtering a collection on an
is
predicate and then doing operations on the subclass further down the chain?
s
filterIsInstance()
?
☝️ 1
w
hmm
ok
in this case, i am checking something within a pair
but ill try to see if I can change it up a bit to work this out
thanks
m
That doesn't work because of erasure. I got bitten by that the other day.
s
If its inside a
Pair
then do a
mapNotNull
to get it converted to the right type
ie.
mapNotNull { p -> (p.first as? Class)?.let { it to p.second} }
w
ok cool.
thanks!