Kotlin Bytecode - How to analyze in IntelliJ IDEA?
Asked Answered
S

3

86

I want to see the compiled bytecode so I can learn more about how it works under the cover. I'm using IntelliJ IDEA 15 but can't find a way to see the bytecode. What am I missing?

Sansbury answered 21/2, 2016 at 15:35 Comment(0)
S
127

IntelliJ IDEA comes with a bytecode viewing tool for Kotlin:

Tools → Kotlin icon Kotlin → Show Kotlin Bytecode

Also available through Ctrl / ⌘+Shift+A as Show Kotlin Bytecode action.

It's a great tool that can jump to the corresponding bytecode when you move around in the source file. And it updates the bytecode on the fly whenever the source changes.


Also, I'd like to recommend jclasslib Bytecode Viewer as an external tool for low-level class files analysis (such as inspecting constant pools). Now it is also available as an IntelliJ IDEA plugin.

Stansbury answered 21/2, 2016 at 16:20 Comment(1)
@Sansbury And shortcut ctrl+shift+a (windows and linux) or shift-command-a (mac) is very usefull. Press this shortcut and then type kotlin!Lolitaloll
A
5

I use https://javap.yawk.at/ to view byte code online. Set "Kotlin" as the input language and you are good to go.

It even has an option to see the decompiled Java code via Procyon, but it might crush from time to time.

Andradite answered 27/2, 2017 at 12:59 Comment(0)
O
4

Just adding to the above answer.

Tools → enter image description here Kotlin → Show Kotlin Bytecode

Now, in the bytecode view, there is also an option to decompile the bytecode to Java. So, you can actually see both the bytecode and the equivalent java code in intellij. You even have an option to convert using JVM 8 target.

Operatic answered 19/9, 2018 at 6:21 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.