A receiver parameter is an implicit parameter passed to a Kotlin extension function, extension property, or lambda that defines the execution context (Documentation Index
Fetch the complete documentation index at: https://docs.syntblaze.com/llms.txt
Use this file to discover all available pages before exploring further.
this) for that block of code. By specifying a receiver type, the compiler exposes the public members of that type directly within the body without requiring explicit qualification.
The receiver parameter is defined by prefixing the function name, property name, or function type with the target type, followed by a dot (.).
Extension Functions
When declaring an extension function, the type being extended is the receiver type. The instance on which the function is invoked becomes the receiver parameter.Extension Properties
Receiver parameters also apply to extension properties. Because extension properties cannot store state (they lack a backing field), the receiver parameter is utilized within custom getters and setters to compute or mutate the property value.Nullable Receivers
A receiver parameter can be declared as nullable by appending? to the receiver type. This allows the extension to be invoked on null references without requiring the safe-call operator (?.). The function body is responsible for handling the nullability of the receiver parameter.
Function Literals with Receiver
In higher-order functions, defining a function type with a receiver (e.g.,String.() -> String) transforms a standard lambda into an extension lambda, altering its lexical scope to include the receiver’s members.
Crucially, at the type-system level, function types with receivers are interchangeable with standard function types that take the receiver as their first explicit parameter (e.g., (String) -> String).
JVM Compilation Mechanics
Kotlin does not modify the original classes to inject receiver parameters. At the JVM bytecode level, the Kotlin compiler translates the receiver parameter into an explicit first argument of the compiled method. For top-level extensions, the compiler generates a static method. For member extensions (extensions declared inside another class), the compiler generates an instance method where the extension receiver is passed as the first regular parameter. A top-level Kotlin extension function:Static Resolution
Receiver parameters are resolved statically at compile time based on the declared type of the variable, not dynamically based on the runtime type. They do not participate in virtual method dispatch.Dispatch Receiver vs. Extension Receiver
When an extension function is declared as a member inside another class, two distinct implicit receivers exist in the same scope. It is critical to distinguish between them, as only one is a true receiver parameter:- Dispatch Receiver: The instance of the enclosing class where the extension is declared. This is an implicit receiver that participates in virtual dispatch, but it is not a receiver parameter.
- Extension Receiver: The instance of the type being extended. This is the actual receiver parameter, and it is resolved statically.
this syntax is required.
Master Kotlin with Deep Grasping Methodology!Learn More





