Delegation
KOTLIN › Types & Classes
Drills Kotlin's by keyword for class delegation and property delegates.
Delegation is a frequent Kotlin interview topic because it shows you understand composition over inheritance and how the compiler rewrites property access. Interviewers test whether you know the difference between interface delegation and property delegates, the getValue/setValue operator contract, and the behavior of standard delegates like lazy, observable, and vetoable. Expect questions probing subtle gotchas such as the delegate-can't-see-overrides rule and lazy thread-safety modes.
What this covers
- Class/interface delegation with by to favor composition over inheritance
- Standard property delegates: lazy, observable, vetoable, and map-backed
- Writing custom delegates via getValue/setValue operator functions
- ReadOnlyProperty vs ReadWriteProperty and the val vs var requirement
- lazy thread-safety modes: SYNCHRONIZED (default), PUBLICATION, NONE
- Compiler translation: the hidden prop$delegate field and provideDelegate
Study this topic
- Delegation explained: the guided lesson
- 14 practice quiz questions
- 9 revision flashcards
- Delegation interview questions and answers