Last updated 1 year ago by Marcin Moskalakotlin
We’ve already discussed difference between function literal and function type. Although, Kotlin introduced extension functions and it needed also special type and literals to work with them. They are called function literal with receiver and function type with receiver.
Let’s start from the beginning. Here is a simple example of extension function:
fun Int.square() = this * this
println(2.square()) // Prints: 4
We’ve told that argument with Int is passed to function’s extension receiver, and this or implicit calls reference to it. If we need to associate this function with the property then we can use function reference: