Vitali Plagov
12/21/2021, 1:13 PMapply{}
function inside. Like:
fun Foo.myFun() {
bar.apply {
this.doA()
this.doB()
this.doC()
}
}
this
here refers to the type of bar
, not to the type of Foo
How can I use the instance of Foo
inside the bar.apply{}
?Joffrey
12/21/2021, 1:17 PMthis@myFun
to refer to the receiver of the function. But this is only necessary if there is an ambiguity. You can also not use this
at all and simply call the methods/properties of Foo
directlyVitali Plagov
12/21/2021, 1:40 PMFoo
w/o specifying this
explicitlyJoffrey
12/21/2021, 1:43 PMthis
is optional, unlike in JS. It's only necessary when there is ambiguity