Qualified this from extension method


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


I’m not sure that you can.


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