```abstract class A { abstract inner class B :...
# getting-started
c
Copy code
abstract class A {
    abstract inner class B : A() {
        init {
            // How can I access the outer class?
        }
    }
}
In that example,
this
refers to the class
B
,
this@A
refers to the parent class. How can I access the outer class?
m
easiest way is to declare a
val
in the proper scope:
Copy code
abstract class A {
  val a = this;

  abstract inner class B : A() {
    init {
      // use `a` here
    }
  }
}
c
It doesn't seem to work for me, it still uses the parent's instead of the outer class.
It's weird because the bytecode must have an instruction for this (since it's possible in Java), but it seems like there is no syntax to access it from Kotlin?
v
Make it a
private val
, then it works. Because you cannot access it from subclass, but within that scope.
K 1
c
Indeed! Thanks.
v
Look at his playground link
Hm, yeah, indeed. I just took the OP word for truth, my bad.
👍 1