latriple.blogg.se

Kotlin static
Kotlin static





kotlin static

Public static final #17= #13 of #2 // Companion=class Math$Companion of class MathĪs the bytecode represents, Kotlin compiles the companion object as a static inner class. Public static final Math$Companion Companion ġ: invokespecial #8 // Method java/lang/Object."":()Vĥ: invokespecial #16 // Method Math$Companion."":(LDefaultConstructorMarker )VĨ: putstatic #20 // Field Companion:LMath$Companion Now, let’s take a peek at the generated JVM bytecode using the javaptool: > javap -c -p Math In order to verify this assumption, first, let’s compile the Math.kt file: > kotlinc Math.ktĪfter compilation, there will be three class files: > ls *.classĪs shown above, one class file is for the main function, one for the Math class, and one for the companion object.







Kotlin static