Hello, please, explain why autocasting not workin...
# announcements
e
Hello, please, explain why autocasting not working. i have the code: if (fragment is SearchFragment?) { (fragment as SearchFragment?)?.setOnlineNumber(online_number) } but if i write: if (fragment is SearchFragment?) { (fragment)?.setOnlineNumber(online_number) } it tells me "Unresolved reference: setOnlineNumber"
a
You should at least use ``` to separate code from text. Otherwise it is not readable. In your second sample round brackets are not needed, but I do not think it affects the result.
👍 1
c
Hm... it works for me...

https://kek.gg/i/3m9JyD.png

k
I
fragment
a local variable?
a
What version of kotlin? Also if var it will not smart cast if it's a mutable property
c
@agrosner actually it should smart-cast even for var if it's local and isn't modified between assignment and the check.
a
yeah mutable property i meant of class
k
Well an immutable one from another class is also not autocasted, since the getter might not always return the same thing.
And even if it did for now the behavior might change with binary compatibility.
a
if its a computed property it autocasts. if it has a custom getter than no