June 2018
Intermediate to advanced
316 pages
6h 34m
English
The const modifier allows you to declare compile-time constants. We can remove this modifier from our example and the version decompiled to Java will look as follows:
public final class MainKt { private static final int compileTime = 5; public static final int getCompileTime() { return compileTime; } public static final int compileTimeFunction() { return compileTime + compileTime; }}
As you can see, now the MainKt class contains the extra getCompileTime() function. In the bytecode, you can see that the MainKt class also contains the static <clinit>()V function:
static <clinit>()VL0LINENUMBER 3 L0ICONST_5PUTSTATIC mastering/kotlin/performance/chapter6/constants/MainKt.compileTime : IRETURNMAXSTACK = 1MAXLOCALS = 0
Read now
Unlock full access