Consider this piece of code:
var foo: Foo? = null
if (foo != null) {
foo!!.bar()
}
If I omit the two !! I get this error:
Smart cast to 'Foo' is impossible, because 'foo' is a mutable property that could have been changed by this time
This is about concurrency, right? Well, there is no concurrent code that might change the value of foo
.
Of course, it works with the two !!. However, I was wondering if this is the most idiomatice way or if there is a better way, without the two !!.
I know I could just foo?.bar()
in this particular case. But the question is about whether I can treat foo
as Foo
instead of Foo?
somehow after I've checked that it's not null
.