Automated Java to Scala source code conversion? [closed]

别等时光非礼了梦想. 提交于 2019-11-28 04:19:54

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.

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.

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.

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

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).

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