Kotlin Decompiler generates erroneous code - Is it possible to prevent?

霸气de小男生 提交于 2019-12-12 04:17:57

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!