The moose likes Scala and the fly likes How Scala class compile to Java file and class file Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Java Interview Guide this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Languages » Scala
Bookmark "How Scala class compile to Java file and class file" Watch "How Scala class compile to Java file and class file" New topic

How Scala class compile to Java file and class file

Nishan Patel
Ranch Hand

Joined: Sep 07, 2008
Posts: 689

I have seen Scala after compile to class file and try to understand how it works, but it seems lot of methods generated which dose not give fair idea about it.



how these all above methods compile to Java class files with auto generated methods and how it woks ?

Thanks, Nishan Patel
SCJP 1.5, SCWCD 1.5, OCPJWSD Java Developer,My Blog
Joe Harry
Ranch Hand

Joined: Sep 26, 2006
Posts: 10033

I'm not that familiar with a Scala compiler, but if you think about the fact that a Scala function compiles to a class, you can reason out why you see so many class files after compilation. If you are trying to learn Scala, I would first focus on the core language concepts than understanding the Scala compiler.

SCJP 1.4, SCWCD 1.4 - Hints for you, Certified Scrum Master
Did a rm -R / to find out that I lost my entire Linux installation!
Montana Burr

Joined: May 04, 2014
Posts: 20
I'm thinking the Scala compiler first converts the Scala code to Java code, then uses Java's Compiler API to have that code compiled.

Note that you will, in all probability, eventually use classes that came with your Scala installation. For example, a Map is a Scala collection, and therefore is not a Java Map.
chris webster

Joined: Mar 01, 2009
Posts: 2295

Nishan Patel wrote:I have seen Scala

Joe's right: you should probably learn how to write Scala first, so you can understand how it's different from Java. Then you might have a better understanding of why the compiler makes certain choices. Scala doesn't use static methods like Java, but it uses (Singleton) companion objects alongside a class, which provide equivalent abilities (and more) e.g acting as factories. The compiler has to translate this into byte code for the JVM, but the whole point of using a language like Scala is to move beyond the limitations of Java, so why not explore the Scala language rather than the compiler?

No more Blub for me, thank you, Vicar.
I agree. Here's the link:
subject: How Scala class compile to Java file and class file
It's not a secret anymore!