问题
class CheckInventory(target: Target) : Command(target) {
}
When decompiling the above Kotlin code using the IntelliJ's "Show Kotlin bytecode" option, it keeps generating a statement above the super()
call:
class CheckInventory extends Command {
public CheckInventory(Target target) {
Intrinsic.checkParameterIsNotNull(target, "target");
super(target); //error, must be first call
}
}
There are a few other issues, such as generating top-level classes with an access modifier for WhenMapping:
public class MyClass {
}
public final class MyClass$WhenMappings { //error, shouldn't be public
}
I checked for both Kotlin and IntelliJ updates, and I'm using the latest version for both.
At first I thought it may had to do with poorly written Kotlin code, but even the simplest code files seem to require some sort of check/generation that's illegal in Java.
Question
Is there any way to ensure the decompilation process stays within bounds of the Java language rules?
回答1:
No. The Java decompiler in IntelliJ IDEA is designed for decompiling Java source code. The Kotlin compiler generates different bytecode patterns from the Java compiler, so the Java decompiler does not always produce output which is valid Java code.
来源:https://stackoverflow.com/questions/43075242/kotlin-decompiler-generates-erroneous-code-is-it-possible-to-prevent