I would like to access the scope of the calling class when creating an "anonymous inner class" in Kotlin. What would be the equivalent of Java's OuterScope.this syntax? example :
OuterScope.this
open class SomeClass { open fun doSomething() { // ... } } class MyClass { fun someFunc() { object : SomeClass() { override fun doSomething() { super<SomeClass>.doSomething() // Access the outer class context, in Java // this would be MyClass.this } } } }
this@MyClass
JFYI: the same syntax for access to receiver of extension function:
fun MyClass.foo() { // in some nested thing: this@foo //... }
Kotlin Reference: This expressions
2.1m questions
2.1m answers
60 comments
57.0k users