Search⌘ K
AI Features

Built-in Standard Delegates

Learn how to use Kotlin's built-in standard delegates such as lazy for deferred execution, observable to track property changes, and vetoable to control property updates through conditional logic. This lesson helps you implement efficient and adaptable property management techniques for clean and effective Kotlin code.

Kotlin provides a few built-in delegates that we can readily benefit from. The Lazy delegate is useful to defer creating objects or executing computations until the time the result is truly needed. The observable delegate is useful to observe or monitor changes to the value of a property. The vetoable delegate can be used to reject changes to properties based on some rules or business logic. We’ll explore these features in this section.

It’s OK to get a little lazy

Decades ago John McCarthy introduced short-circuit evaluation to eliminate redundant computations in Boolean logic—the execution of an expression is skipped if the evaluation of an expression ahead of it is enough to yield the result. Most programming ...