Im curious about `?` and `!!` operators. Let's say...
# getting-started
b
Im curious about
?
and
!!
operators. Let's say I have a fun that should be fired on a service that show/hide something, like: bubblesService.addBubble(), but the service itself is nullable.
bubblesService: BubblesService? = null
. At some point im sure it is not null, and on the next line after
bubblesService = binder.service
I want to call
bubblesService.addBubble()
. Even tho I theoriticaly know its not null, I dont want to call it on a null referencje object. So I can say bubblesService!!.addBubble(), since I know its not null. But I can also call bubblesService?.addBubble() and do the same, but In case if (for any reason) it is null I wont crash, using
?
. So, I don't see any advantage of using
!!
if I can simply use
?
and dont run the code that could otherwise crash the app