Qualified this from extension method


#1

How do you access an outer class from an extension function?

class A (val foo: String) {
  inner class B (val bar: String){
    fun printme1() {
      println(foo) //works
      println(this@A.foo) //works
    }
  }
}

fun A.B.printme2() {
  println(bar) //Works fine
  println(foo) //Unresolved reference: foo
  println(this@A.foo) // Unresolved reference: @A
}

#2

I’m not sure that you can.


#3

You have to expose a public reference to A, otherwise it is private.