Compiling Scala scripts. How works scalac?
Posted
by
Arturo Herrero
on Stack Overflow
See other posts from Stack Overflow
or by Arturo Herrero
Published on 2012-03-19T17:17:07Z
Indexed on
2012/03/19
18:04 UTC
Read the original article
Hit count: 351
Groovy
Groovy comes with a compiler called groovyc
. For each script, groovyc
generates a class that extends groovy.lang.Script
, which contains a main method so that Java can execute it. The name of the compiled class matches the name of the script being compiled.
For example, with this HelloWorld.groovy
script:
println "Hello World"
That becomes something like this code:
class HelloWorld extends Script {
public static void main(String[] args) {
println "Hello World"
}
}
Scala
Scala comes with a compiler called scalac
. I don't know how it works.
For example, with the same HelloWorld.scala
script:
println("Hello World")
The code is not valid for scalac
, because the compiler expected class or object definition, but works in Scala REPL interpreter. How is possible? Is it wrapped in a class before execution?
© Stack Overflow or respective owner