Automated Java to Scala source code conversion? [closed]

六月ゝ 毕业季﹏ 提交于 2019-11-30 05:56:46

问题


(Yes I know I can call Java code from Scala; but that is pointless; I want to DELETE the Java code, not keep it around and have to look at it and maintain it forever!)

Are there any utilities out there to convert Java source to Scala source?

I believe theoretically it should be possible to accomplish with minimal lossage.

I have found this but it seems inactive, probably buggy/incomplete... http://sourceforge.net/projects/java2scala/

Any alternatives?


回答1:


IntelliJ kinda, sorta, does this. You need to open a project with your Java sources. You can then copy/paste expressions, methods, or entire classes in to a .scala file. This converts to equivalent Scala code.

The fidelity of conversion isn't perfect, and, for this reason, it doesn't support a bulk conversion yet.

I recommend using the latest version of IntelliJ and the Scala Plugin. The Community Edition is free.

Aside from this, Paul Phillips once started the Scalify project to translate code from Java to Scala (or, potentially, your favourite language), and even improve it in the process! He explains the concept in this video. However this effort was stalled, presumably because he turned his attention to directly contributing to the Scala compiler and standard library.




回答2:


In IntelliJ IDEA theres is a refactoring called "Convert to Scala". It's under Refactor menu (after you install Scala plugin) Ctrl+Shift+G. So you don't need to play with copy/paste.

Just make sure you have a java file opened, there is no this option if it's a scala or other file.




回答3:


I just published the following tool : Scalagen. I tried Jatran as well, but was frustrated with some bugs and difficult integration. Scalagen is extensible and comes with a Maven plugin.




回答4:


You can use online Java to Scala converter which uses Scalagen library.




回答5:


http://code.google.com/p/jatran/

(I haven't used this)


noticed this, Mar 2012: http://blog.mysema.com/2012/03/scalagen-java-to-scala-conversion.html




回答6:


I don't think it's possible to automatically convert Java to Scala in the general case. Many of the lower-level constructs in Java don't exist in Scala (e.g. fields and static members), Scala places limitations on constructors that don't exist in Java, and Scala doesn't have raw types like Java (generics without the generic parameters specified).



来源:https://stackoverflow.com/questions/2484064/automated-java-to-scala-source-code-conversion

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!