AbdullahCoder
AbdullahCoder

Reputation: 3

Do I have to null check every time before referencing an element in view binding?

So this isn't really a issue, I am just curious, do I really have to null check every time I use view binding? I find it a bit annoying having to put the question mark every time (binding?.[layout item]).

Can somebody please give me a solution to this if it's possible?

Upvotes: 0

Views: 91

Answers (1)

Ivan Wooll
Ivan Wooll

Reputation: 4332

The only reason you would be doing this is if you had marked the Binding object as nullable, e.g. lateinit var binding MainActivityBinding?. Which there is no need for.

Upvotes: 0

Related Questions