Compiling Scala scripts. How works scalac?
- by Arturo Herrero
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?