Skip to content
Justice Tech School

Extension Functions

Add functions to existing types without inheritance.

Example
fun String.shout() = this.uppercase() + "!"
fun Int.isEven() = this % 2 == 0
println("hello".shout())
println(4.isEven())

Exercise

Receiver type.

fun .shout() = this

Quiz Test

What is this inside an extension?

These free lessons are for learning. Join a full course for projects, mentor feedback and a verified certificate.