What is the functional difference between the two lines of code:
private val binding = viewBinding(Fragment::bind)
private val binding by viewBinding(Fragment::bind)
I tried reading this stack overflow post on what is the by keyword used for in Kotlin but, it says that it replaces the getter and setter functions to the expression following the by keyword so why have it at all if you can just use = instead, to set the object to a particular value?
'=' means
bindingis assigned to the value ofviewBinding()method immediately. It doesn't require any other calls.'by' is used to set a delegation. 'by' act as a getter of the
bindingto theviewBinding()method result. What is does actually, binding won't be result ofviewBinding()until binding itself is not accessed. By using 'by' you can trigger a lazy initialization.more at Delegated properties