Property Delegation

This Atom is Under Construction

A property can delegate its accessor logic.

You connect a property to a delegate with the by keyword, as var/val property by delegate. The delegate must contain one or two specially-defined functions, called when the delegated property is accessed:

  1. For reading: operator fun getValue(delegator: Any?, prop: KProperty<*>)

  2. For writing: operator fun setValue(delegator: Any?, prop: KProperty<*>, value: TypeToWrite)

If the delegated property is a val, only the first function is required.

End of sample. See AtomicKotlin.com for full early-access book.



Previous          Next

©2018 Mindview LLC. All Rights Reserved.