Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

How Scala class compile to Java file and class file

 
Nishan Patel
Ranch Hand
Posts: 689
Eclipse IDE Java Scala
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 ?

 
Joe Harry
Ranch Hand
Posts: 10122
3
Eclipse IDE Mac PPC Ubuntu
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Montana Burr
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 2407
32
Linux Oracle Postgres Database Python Scala
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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?
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic