Skip to main content
InterviewHubPRO
Section Overview
Q45

Question 45 of 50

Part 3: K2 Compiler, KMP, Advanced Metaprogramming & Optimization (25 - 35)

90%
Kotlin & Coroutines (50 Qs)•Part 3: K2 Compiler, KMP, Advanced Metaprogramming & Optimization (25 - 35)

Kotlin Delegated Properties: `by lazy`, `by Delegates.observable()`, and custom delegates.

senior LevelRxJSPerformance

In Simple Words: Delegates property getter and setter logic to an external reusable object:

  • by lazy { ... }: Computes the value once on first access and caches it thread-safely.
  • by Delegates.observable(initialValue) { prop, old, new -> ... }: Triggers a callback whenever the property mutates.
  • Custom Delegate: Implement ReadOnlyProperty<R, T> or ReadWriteProperty<R, T> with getValue and setValue methods.