Problem Statement
Explain built-in property delegates in Kotlin including lazy, observable, and vetoable.
Explanation
Lazy delegate defers property initialization until first access with thread-safe caching by default, perfect for expensive computations or properties depending on unavailable state at construction time. Use lazy when initialization is costly and the property might not be used.
Observable delegate from Delegates dot observable notifies a callback whenever the property changes, receiving old and new values, useful for tracking changes or triggering side effects on updates. Use observable for logging, validation, or updating dependent state when properties change.
Vetoable delegate from Delegates dot vetoable is like observable but the callback returns boolean determining whether to accept the change, enabling validation before assignment. If the callback returns false, the property retains its old value, providing declarative validation.
You can create custom delegates implementing getValue and setValue operators, enabling reusable property behavior patterns. Map delegation stores properties in a Map useful for dynamic properties or JSON parsing, and notNull delegate provides late initialization with runtime checks.
