Paradoxically, I have found lots of discussions on the Internet about this, too many, starting with a
thread in the old Scala forum. I have also noticed a trend of people
asking for this and then giving up and using some workaround, mostly 5 to 3 years ago.
AFAIK, there is no standard or direct way to generate Java code from Scala code. However, Scala code can be compiled into Java bytecode (quite standard process), and Java bytecode can be decompiled into Java code again, thus generating Java code.
As far as I could see, there are quite a few tools for this, and I guess they may work with varying degrees of success. I would like to know the current state of the art in this, if possible. Systematically testing all possibilities, with different Scala programs, checking the results, etc. would take very long. I hope the community knows enough to guide that search, ideally enough to avoid that search, or perhaps someone has already done that and can pinpoint a solution.
In particular, I am interested in:
- Generating Java code that works, readability is always good but secondary in this case.
- Using a good (free at least as beer, if possible as speech) tool that generates good Java code, there are quite a few. A nice feature would be a command line mode, but the previous point is the most relevant aspect.
- Setting the best flags in scalac to make the decompiler job easier (so here we have a combinatorial explosion with the previous point). One flag may be -g:notailcalls, the target Java version may also be relevant.
- I don't mind restricting myself from using some Scala expressions that may cause trouble.
I think this is a recurrent question, so maybe we can put together the knowledge that each one has extracted so far, any contribution, no matter how small, is welcome. In the end there may be several solutions that may be better or worse suited for different tasks, and having that information would be quite useful IMHO, as there isn't much usable information on the Internet, but mostly people discussing that it's very hard, maybe impossible, but the point is: what can be done, how far can we get, what is the current state of the art. Apparently
something can be done, but that's as much as I know.
Thank you, and sorry if there's anything wrong with my post, this seems to be a bit of a taboo lately.