This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
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 Android Security Essentials Live Lessons this week in the Android 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
Author

How Scala class compile to Java file and class file

Nishan Patel
Ranch Hand

Joined: Sep 07, 2008
Posts: 684

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.

like,



&



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: 9345
    
    2

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
Greenhorn

Joined: May 04, 2014
Posts: 14
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
Bartender

Joined: Mar 01, 2009
Posts: 1621
    
  13

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: http://aspose.com/file-tools
 
subject: How Scala class compile to Java file and class file
 
Similar Threads
files with no public classes...
constructor to add to an array list
overriding public static void main(String[] args)
problem with code....
Scala not compiling on Eclipse