Decompiling Kotlin code to Java and JVM bytecode
In this recipe, we are going to learn how to easily decompile our Kotlin files to see how their corresponding JVM bytecode is implemented and what the bytecode's corresponding Java implementation would look like. This can help you to discover how various Kotlin concepts were implemented under the hood. It can also be helpful for code-debugging and optimization.
Getting ready
Let's create a new Kotlin file, named Recipe4.kt
, that contains the following sample implementation in order to see its bytecode translation:
data class A(val a: String = "a") { companion object { @JvmStatic fun foo(): String = "Wooo!" } }
How to do it...
- Open the
Recipe4.kt
file in IntelliJ. - Choose the
Show Kotlin Bytecode
option from theTools/Kotlin
menu. The box will present the JVM bytecode implementation. - Click the
Decompile
button in theKotlin Bytecode
view. The corresponding Java implementation will be decompiled from the bytecode and will appear in the new window...