Purpose of with & without underscore variable view binding

Viewed 124
1 Answers

The getter on the second variable (binding) uses the !! operator to assert that the variable is non-null when accessed.

Essentially the backing field (_binding) is nullable in order to represent the state before onCreateView and after onDestroyView whereas the getter provides an easy way to access the field without scattering null checks or assertions elsewhere in your code.

Related