TE
TechEcho
Home24h TopNewestBestAskShowJobs
GitHubTwitter
Home

TechEcho

A tech news platform built with Next.js, providing global tech news and discussions.

GitHubTwitter

Home

HomeNewestBestAskShowJobs

Resources

HackerNews APIOriginal HackerNewsNext.js

© 2025 TechEcho. All rights reserved.

Java to Scala converter

110 pointsby lukaxover 11 years ago

14 comments

scottjadover 11 years ago
This is just a simple front-end&#x2F;demo. The real work is being done by a separate project at <a href="https://github.com/mysema/scalagen" rel="nofollow">https:&#x2F;&#x2F;github.com&#x2F;mysema&#x2F;scalagen</a>.<p>I kind of wished this site was written in Java and run through scalagen with the output being run as an additional meta-demonstration.
ben0x539over 11 years ago
I don&#x27;t know scala so maybe I&#x27;m missing something, but does this just break with functions that start with a switch statement? eg.<p><pre><code> public static void main(String[] args) { switch (42) {} System.out.println(&quot;Hello World!&quot;); } </code></pre> converts to<p><pre><code> def main(args: Array[String]) 42 match { } </code></pre> dropping the println.<p>Edit: It also seems to be dropping autoincrement&#x2F;decrement, and random other blocks of code I&#x27;ve looked at, so I guess it&#x27;s still in a fairly early stage.<p>Definitely a cool project though :)
评论 #6461287 未加载
adandyover 11 years ago
I also noticed this in IntelliJ when I went to copy some Java into a Scala project. As I began converting the Java code to Scala after the copy I was extremely confused when I found that the pasted code was already converted for me.
评论 #6458441 未加载
unclebucknastyover 11 years ago
Earnest question: who is the target audience here? If Java and Scala can be intermixed in the JVM, and the generated Scala code is not very idiomatic, then how would this be used?
评论 #6459184 未加载
ExpiredLinkover 11 years ago
A Scala to Java converter would be needed more. Early adopters are disenchanted with Scala.
评论 #6458527 未加载
评论 #6459204 未加载
评论 #6458485 未加载
评论 #6458517 未加载
评论 #6459027 未加载
agibsoncccover 11 years ago
This is a neat project. I have a giant codebase I&#x27;d like to try this on. Depending on the output, this might be the kick in the pants I need to get in to scala full time.
评论 #6457867 未加载
评论 #6457808 未加载
yareallyover 11 years ago
Intellij IDEA has had Java to Scala conversion built into it for a while (as well as Java to Kotlin, Jetbrain&#x27;s new JVM Scala-like language). I&#x27;m not sure how Jetbrain&#x27;s tool compares to the one in the link above, but the conversion result in Intellij varies by how complicated and dependent the code is on other packages&#x2F;libraries. Converting an entire class file tends to work out much better than a single method.<p>I initially used it to convert some Android code in Java to Scala, but much of the time you have to end up rewriting that as well, since it&#x27;s generally results in very non-idiomatic Scala code. Still useful for someone learning Scala though as others have pointed out.<p>The Scala plugin is free though and comes with the community edition of Intellij for anyone wanting to try it out. Basically you just copy&#x2F;paste some Java code from the current project into a Scala file or right click on the Java file and select &quot;convert.&quot;
zidarover 11 years ago
This looks great. Now if only Scala would play nice with Android, there would be no need to look back at java at all.
评论 #6457676 未加载
dkhenryover 11 years ago
So now I am really wondering. What is the sub java parts of the JVM that need to be implemented to completely free Scala from the JVM ( i.e. what C interfaces are needed to allow scalc to compile to LLVM or comparable VM)
评论 #6457783 未加载
评论 #6458247 未加载
评论 #6457856 未加载
ensmotkoover 11 years ago
Wow, this is awesome. Have you tried running it on a larger Java codebase?
评论 #6457276 未加载
mark_eijsermansover 11 years ago
Now we just need a OOP -&gt; FP converter ;)
评论 #6458633 未加载
orphover 11 years ago
Would love the opposite, a scala -&gt; java converter.
mcavover 11 years ago
Cool, has anyone made something similar for Clojure?
评论 #6458061 未加载
评论 #6459172 未加载
评论 #6457781 未加载
anonymoushnover 11 years ago
enums are converted into code that does not compile.
评论 #6458356 未加载