Why convert Kotlin to Java if Kotlin is the "new Java"?
\n\nIt may seem like a paradox: you write in Kotlin, but then want to get Java code. Why? In reality, there are many situations. You might inherit a project written in Kotlin, but your team isn't ready to switch to it yet. Or you are learning Kotlin by comparing it with Java — one of the most effective ways. Or perhaps you need to integrate a Kotlin library into an old Java project and want to understand how a particular method works.
\n\nIn any case, the question "How to convert a Kotlin source file to a Java source file" is one of the most popular on Stack Overflow (thousands of views). And today we will cover it from start to finish. You will learn how to officially (via IntelliJ IDEA) and unofficially (via decompilation) turn .kt into .java, what pitfalls await you, and what to do if nothing works.
1. Direct Conversion: Myth or Reality?
\n\nLet's warn you upfront: a one-to-one reverse conversion Kotlin → Java does not exist. Kotlin is not just "sugar" on top of Java; it has its own semantics: null-safety, coroutines, extension functions, data classes. Java doesn't have such luxuries. Therefore, any converter will produce approximate code that often looks bulky and contains calls to internal Kotlin functions (e.g., Intrinsics.checkNotNullParameter()).
But that doesn't mean the task is impossible. There are three main approaches:
\n\n- \n
- Bytecode decompilation — the most accurate method, built into IntelliJ IDEA and Android Studio. \n
- JADX — for Android developers when there are no source files, only an APK. \n
- Online converters — a quick option for small snippets. \n
2. Method #1: Decompilation via IntelliJ IDEA (Most Reliable)
\n\nIf you have the original .kt file, you can open it in IntelliJ IDEA (or Android Studio) and ask the IDE to show the equivalent Java code. How to do this?
\n\nStep 1. Open the Kotlin file
\nLet's say we have a simple Kotlin class:
\n\n// File: Person.kt\ndata class Person(val name: String, val age: Int) {\n fun greet() = "Hello, my name is $name"\n}\n\nStep 2. Run decompilation
\nIn the IntelliJ menu, select Tools → Kotlin → Show Kotlin Bytecode. A panel with bytecode will open. In this panel, click the Decompile button — and you will see the Java version of your file.
\n\nHere is what the IDE will output for our Person.kt:
// Java decompilation\npublic final class Person {\n @NotNull\n private final String name;\n private final int age;\n\n @NotNull\n public final String getName() {\n return this.name;\n }\n\n public final int getAge() {\n return this.age;\n }\n\n public Person(@NotNull String name, int age) {\n Intrinsics.checkNotNullParameter(name, "name");\n super();\n this.name = name;\n this.age = age;\n }\n\n @NotNull\n public final String greet() {\n return "Hello, my name is " + this.name;\n }\n\n // equals(), hashCode(), toString() — generated automatically\n}\n\nImportant: The code contains calls to Intrinsics — this is part of the Kotlin runtime. If you copy such code into a project without Kotlin dependencies, it will not compile. You will either need to add kotlin-stdlib or manually remove these checks.
3. Method #2: JADX — For Android Without Source Code
\n\nIf you only have an APK file and want to understand how a particular Kotlin class is implemented, use JADX. It is a decompiler that turns DEX bytecode into readable Java code. Kotlin classes in an APK are still compiled into JVM bytecode, so JADX will handle it.
\n\nExample: you found a class with a coroutine in an APK. In Kotlin, it might look like