June 2018
Intermediate to advanced
316 pages
6h 34m
English
Inner classes are used rarely, but here is one good example of how to use them:
class Main { inner class Inner { fun printValue() { println(value) } } private var value = "Value"}
Here's the decompiled version of this code:
public final class Main { private String value = "Value"; // $FF: synthetic method public static final void access$setValue$p(Main $this, @NotNull String var1) { $this.value = var1; } public final class Inner { public final void printValue() { String var1 = Main.this.value; System.out.println(var1); } }}
The compiler considers Main and Inner as two separate classes, and generates special functions to enable the Inner class to access private members of the Main class. In the bytecode, you can see that the ...
Read now
Unlock full access