Extension Functions & Properties
KOTLIN › Types & Classes
Adding behavior to existing types via statically-resolved extensions, plus Android KTX.
Extensions are everywhere in modern Android and KTX, so interviewers use them to probe whether you understand that they are syntactic sugar over static helper calls, not real inheritance. Expect to be tested on static dispatch versus virtual dispatch, member-versus-extension precedence, nullable receivers, why extension properties have no backing field, and when reaching for an extension actually helps readability versus hiding behavior.
What this covers
- Extensions resolve statically by the receiver's declared (compile-time) type, with no virtual dispatch or real overriding
- Member functions always win over extensions with the same signature; extensions only add or overload
- Nullable receiver types (T?) let an extension be called on null and check this == null safely
- Extension properties have no backing field, so they need an explicit getter and cannot be initialized
- Receiver scoping: this refers to the receiver, and member extensions juggle a dispatch receiver plus an extension receiver
- Android KTX is a library of extension functions, lambdas-with-receiver, and inline helpers that cut Jetpack/platform boilerplate
Study this topic
- Extension Functions & Properties explained: the guided lesson
- 14 practice quiz questions
- 9 revision flashcards
- Extension Functions & Properties interview questions and answers