It's hard to tell acording to the docs https://kotlinlang.org/docs/reference/extensions.html
so I wonder are receiver object and extension receiver the same? or does the name depends on context?
An extension receiver is a receiver object while a receiver object is either a dispatch receiver or an extension receiver.
Inside a class, you can declare extensions for another class. Inside such an extension, there are multiple implicit receivers - objects members of which can be accessed without a qualifier. The instance of the class in which the extension is declared is called dispatch receiver, and the instance of the receiver type of the extension method is called extension receiver.
class D { fun bar() { ... } } class C { fun baz() { ... } fun D.foo() { bar() // calls D.bar baz() // calls C.baz } fun caller(d: D) { d.foo() // call the extension function } }
In the above example the function foo
has two implicit receivers: C
is the dispatch receiver and D
is the extension receiver. If foo
were declared outside of class C
then it would only have one receiver which would be the extension receiver D
.
In short, a receiver object and an extension receiver can be the same but there is also another type of receiver object called a dispatch receiver.
For more details, see Declaring Extensions as Members - Extensions - Kotlin Programming Language.