0Pricing
Kotlin Academy · Lesson

Extension Functions: Syntax and Dispatch Rules

Write extension functions and understand static dispatch semantics.

What Are Extension Functions?

Extension functions let you add new functions to existing classes without modifying them or using inheritance.

Basic Extension Function Syntax

Prefix the function name with the type you're extending, called the 'receiver type'.
fun String.shout(): String = uppercase() + "!"
println("hello".shout())  // HELLO!
fun Int.isEven() = this % 2 == 0
println(4.isEven())  // true

All lessons in this course

  1. Extension Functions: Syntax and Dispatch Rules
  2. Extension Properties and Computed Extensions
  3. Scoped Extensions and Companion Extensions
  4. Practical Extensions: Context, View & String Helpers
← Back to Kotlin Academy