Search code examples
javagoto

Why do Java decompilers generate code with gotos?


After decompiling a .jar file, I saw this line in the resulting Java code:

for (Iterator i = val.getparts(); i.hasNext(); goto 135)

What does this mean? Why does decompiled Java code contain goto statements if goto doesn't compile?


Solution

  • Most decompilers don't consider the fact that goto is invalid in Java source files. It appears in jars and classfiles because compilers use it to implement the following at bytecode level:

    • if-else statements
    • Loops
    • Switches
    • try-catch-finally blocks