How to Show Kotlin Byte Code in IntelliJ IDEA

The Java bytecode decompiler in IntelliJ IDEA is a built-in tool that allows you to read compiled bytecode as if it were human-readable Java code.

— go to Tools > Kotlin > Show Kotlin Bytecode.
On the top-left corner of the opened window, click “Decompile”. IDEA stuck without any reaction on UI or error messages. After ~20 minutes it showed decompiled code with a message “The file is too large: 23.37M. Showing a read-only preview of the first 2.56M.”. Decompiled code attached.

Let’s say you have a library packed in a .jar file. You just downloaded it from the Internet and don’t have the source code for it. How do you look inside and make sure it actually has what you need?

When you’re new to KotliN. It’ll be really useful to see…what the equivalent in Java would be as you code various Kotlin patterns.Android Studio offers a great tool that lets you decompile your Kotlin code. see the Java version of the bytecode and from there decompile to pure Java. For this example, I’ll create a new Kotlin class. I’ll name it MyDataClass and I’ll set the kind to class and click OK, So now this is just a very simple class…and let’s take a look at what it compiles to in Java.

I’ll go to the menu and select Tools, Kotlin,…Show Kotlin Bytecode.…This is the bytecode that will be generated,…but this isn’t intended to be human readable.…Now click the decompile button…and you’ll see the equivalent in Java.…A simple Kotlin class is the equivalent…of a public final Java class…and that makes sense because in Kotlin…for a class to be a superclass,…you have to declare it.…By default, it’s the equivalent of final in Java.…

If you open a .class file in a text editor, you’ll only see the bytecode that sometimes makes little sense. However, if you open the same file in IntelliJ IDEA, the IDE shows you the human-readable Java code from your .jar, without actually converting .class files into .java files. The yellow notification panel above the editor informs you that you’re reading a decompiled file.

Leave a Reply

Your email address will not be published. Required fields are marked *