Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Automatically convert Scala code to Java code [closed]

Tags:

I have an app written in Scala and some of my team members want a Java version of it. It is a demo app to use another API written in Scala, and they want a Java version of the app to be able to use the API from Java. However, the app is somewhat large and I don't want to manually rewerite in Java (and they don't want to learn Scala). Is there any tool that will automatically generate (readable) Java code from the Scala code?

like image 774
Jus12 Avatar asked Mar 26 '12 22:03

Jus12


People also ask

Can we convert Scala code to Java?

Decompile Scala code to Java In the Project tool window, right-click a Scala library class that you want to decompile. From the context menu, select Decompile Scala to Java. IntelliJ IDEA converts code to Java and opens the converted file in the editor.

Can Java and Scala work together?

Compiling Java and Scala together The Scala compiler allows you to build against both Java classes and Java source code. That way, if you have bidirectional dependency between Java and Scala, you can build them together without worrying about order.

Is Scala fully interoperable with Java?

Of all the alternative JVM languages, Scala's interoperability with Java source code is among the most seamless.


2 Answers

they want a Java version of the app to be able to use the API from Java

Scala classes are usable from Java (since it's all JVM bytecode in the end). Can you just package a jar with your classes for them to use?

like image 153
dhg Avatar answered Sep 26 '22 01:09

dhg


I don't think it's possible to convert from scala back to standard java since Scala does some pretty low-level byte-code manipulation. I'm 90% sure they do some things that can't exactly be translated back into normal Java code.

like image 44
JohnnyK Avatar answered Sep 25 '22 01:09

JohnnyK