Property delegation (standard delegates)

In the previous section, where we discussed delegation, we learned that delegation is a technique of method passing/forwarding.

For property delegates, it almost does the same. A property can pass its getter and setter calls to the delegate and the delegate can handle those calls on behalf of the property itself.

You're probably thinking, what is the benefit of passing getter and setter calls to the delegate? Only the delegate you're using can answer this question. Kotlin has multiple predefined standard delegations for most common use cases. Let's have a look at the following list, containing available standard delegates:

  • The Delegates.notNull function and lateinit
  • The lazy function
  • The Delegates.Observable function
  • The Delegates.vetoble function
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.118.2.225