Blog

Your dream job? Lets Git IT.
Interactive technical interview preparation platform designed for modern developers.

XGitHub

Platform

  • Categories

Resources

  • Blog
  • About the app
  • FAQ
  • Feedback

Legal

  • Privacy Policy
  • Terms of Service

© 2025 LetsGit.IT. All rights reserved.

LetsGit.IT/Categories/Kotlin
Kotlinmedium

Extension functions — what are they and what is a common pitfall?

Tags
#extensions#dispatch#kotlin-basics
Back to categoryPractice quiz

Answer

They let you add functions to a type without modifying its source (syntactic sugar). A common pitfall: extensions are resolved statically by the declared type, so they don’t behave like virtual overrides.

open class Base
class Child : Base()

fun Base.say() = "base"
fun Child.say() = "child"

val x: Base = Child()
println(x.say()) // "base" (static dispatch)

Related questions

Kotlin
Extension functions: how are they dispatched and what is a common pitfall?
#kotlin#extension#dispatch