August 2017
Intermediate to advanced
440 pages
10h
English
Member extension functions and properties are compiled the same way as top-level extension functions and properties, with the only difference being that they are inside a class and they are not static. Here is a simple example of an extension function:
class A {
fun boo() {}
fun Int.foo() {
boo()
}
}
This is what it is compiled to (after simplification):
public final class A {
public final void boo() {
... }
public final void foo(int $receiver) {
this.boo();
}
}
Note that while they are just methods with a receiver as the first parameter, we can do with them everything we can with other functions. Access modifiers work the same way, and if we define the member extension function ...
Read now
Unlock full access