Hi everyone, I'm new to Kotlin and Android with Ko...
# android
d
Hi everyone, I'm new to Kotlin and Android with Kotlin. I have one question about nested classes. There a two ways to nest one class into another class, see https://kotlinlang.org/docs/reference/nested-classes.html. The first one creates a static class. The second one creates a un-static one. The documentation says I can use the second one to access the outer class. For example this Kotlin class
Copy code
class Outer {

    val foo: String? = null

    inner class Inner {

        fun foo() {

            if (foo != null) {
                foo.concat("bar")
            }
        }
    }
}
generates this Java Class
Copy code
public final class Outer {

    @Nullable
    private final String foo;

    @Nullable
    public final String getFoo() {

        return this.foo;
    }
  
    public final class Inner {

        public final void foo() {

            if (this.this$0.getFoo() != null) {
                StringsKt.concat(this.this$0.getFoo(), "bar");
            }
        }
    }
}
My question now is: Is it possible to generate Java code where the inner class uses a WeakReference to access the outer class?