Search code examples
javascalajvmbytecodedecompiler

Scala generated byte code to Java code conversion


I know both Scala & Java generates Byte code from its respective compilers, which can be understood by JVM.

But is there any way i can write Scala code and compile it with Scala compiler and generate Byte code and then using any Java decompiler we can generate respective Java code? Or vice versa.

Is there any tools exists to do this? Is it possible to do this conversion? If not can you explain me why it is not possible?

Thanks.


Solution

  • Scala compiles to ordinary Java bytecode, so there is nothing stopping you from running a regular Java decompiler on it. However, Java decompilers are optimized for decompiling Java code, so the results you get may not be pretty. In particular, you won't see any of Scala's syntax sugar for obvious reasons.

    I am not aware of any dedicated Scala decompilers. As Scala is far more complex, it would be a difficult undertaking to write one.