0

This is just an idle-curiosity question. I don't need the answer for any actual use.

EDIT: Thanks to the person who found the previous question that this one more or less duplicates. That was what I was after

The JVM is a target for many languages other than Java (Scala, Kotlin, Groovy etc.) Often, it can be interesting to decompile, say, a Scala class and see how what Scala does "translates" to Java.

Which led to this question: Are there valid compiled JVM-byte-code classes etc that cannot be decompiled to valid (will compile again to the same effective result) Java source?

The Archetypal Paul
  • 41,321
  • 20
  • 104
  • 134
  • 1
    Yes. The most trivial case is that method names in the JVM spec are defined more leniently than in the Java language spec. For example `true` and `null` are valid according to the JVM spec, but you can't have methods named like that in Java language code. – Joachim Sauer Mar 29 '22 at 10:21
  • 2
    For exampe you can gerneate byte code for overloaded methods that have different return types, thats not possible in Java. E.g: `Sting foo()` and `int foo()` would not compile. – Chriss Mar 29 '22 at 10:25
  • Regarding the actual code within a method, the answer is yes. In Java, you cannot do a forward jump into the middle of a loop, but the JVM goto instruction allows it. – boneill Mar 29 '22 at 15:42
  • 1
    @boneill assuming we’re talking about code that would pass the verifier, it would be easy to decompile such code to *equivalent* Java code by using a loop containing an if statement. Since the OP said “to the same effective result”, that would be enough. – Holger Mar 29 '22 at 15:57

0 Answers0