As you noted, Scala eventually compiles to JVM bytecode. An obvious JVM instruction set instruction that has no Java equivalent is goto .
The Scala compiler can use goto to optimize loops or tail recursive methods. In this case, in Java you will need to emulate goto behavior.
As Antimony hinted, Turing's complete language can at least mimic another Turing language. However, the resulting program can be difficult and suboptimal.
As a final note, decompilers can help. I am not familiar with internal decompilers, but I believe that they rely a lot on templates. I mean, for example, that the original Java f (x) pattern is compiled into the bytecode pattern f '(x), so with a lot of work and experience, some manage to decompile Bytecode f' (y) to the Java source f (y).
However, I have not heard of Scala decompilers yet (maybe someone is working on this).
[EDIT] About what I originally meant by emulating goto behavior:
I had in mind the switch/case expressions inside the loop, and cdshines showed a different way using the labeled break/continue in the loop (although I believe that using “ignored and convicted” functions is not standard).
In either of these cases, to return to an earlier instruction, you need the idiomatic Java loop ( for/while/do-while ) (any other suggestion?). An infinite loop makes it easy to implement, a conditional loop will require more work, but I assume that it is doable.
In addition, goto not limited to loops. To speed up the transition, Java will require other solutions.
Counterexample: C has limitations, but you don’t need to go through such long lengths because there is a goto .
As a related topic, if you are interested in non-idiomatic jumping in Scala, cf this old Q & A is mine . I believe that not only the Scala compiler can generate goto in a way that is not natural in Java, but the developer can have tight control over this with Scala macros.
LabelDef : tagged expression. It is not expressed in the syntax of the language, but is generated by the compiler to simulate while / do-while loops, as well as using a template. In my past tests, it can also be used for advanced transitions. At Scala Internals, developers wrote about removing LabelDef , but I don’t know if and when they will be.
So yes, you can reproduce goto behavior in Java, but because of the complexity involved, this is not what I would call standard Java, IMHO. Perhaps my formulation is incorrect, but, in my opinion, the reproduction of elementary behavior by complex means is an “emulation" of this behavior.
Greetings.