https://kotlinlang.org logo
#getting-started
Title
# getting-started
z

Zhiqiang Bian

10/21/2021, 6:46 PM
Just asking a silly question for a friend of my friend think smart. Is there a plugin to convert a Kotlin module into Java module that can run without issues? The
decompile
function of Android Studio can generate Java files. But they have a lot of IDE highlights and imports from
kotlin.jvm
package, which does not seem to work.
j

Joffrey

10/21/2021, 6:47 PM
But why does the friend of your friend want to do that ? 😁
r

Ruckus

10/21/2021, 6:51 PM
Not really, no. The Kotlin compiler can generate JVM bytecode that cannot be directly represented in Java. Sure you can rewrite those parts to valid (even idiomatic) Java (as in, different code that accomplishes the same task), but there's a limit to which that can be done automatically, as it requires understanding intent instead of process.
z

Zhiqiang Bian

10/21/2021, 6:53 PM
The excuse I heard is that s/he is working on a part-time job, so s/he does not want to learn Kotlin . Please tell me the task is impossible 🙏.
@Ruckus Thank you, Sir. You just freed me from Mission Impossible 🙏.
t

TwoClocks

10/21/2021, 7:51 PM
there is a plugin for intellij that will show you the expected java-code from some kotlin-code. But it doesn't replace calls to the kotlin stdlib w/ calls to the java stdlib. So event if you wanted to run that java code, you'll still need the kotlin run-time.