Does it ever make sense to use double-bang (!!) after safe operator (?.) in a kotlin expression, considering non-nullable properties of a nullable receiver are nullable?
Copy code
class Foo(val bar: Bar)
var foo: Foo? = null
foo?.bar!! // will crash when foo is null đŸ’€
p
prasham.h.trivedi
03/28/2018, 7:30 AM
This code will throw exception when foo is not null but bar is null.
v
vibin
03/28/2018, 7:31 AM
that’s true, but my point was it’ll also throw exception when foo is null and bar is not
vibin
03/28/2018, 7:32 AM
updated the snippet to make it clear
p
prasham.h.trivedi
03/28/2018, 8:34 AM
when foo is null. Foo.bar will also be null. I don't think it's possible to have non null member when object itself is null