Reputation: 1685
As per the Scala tutorials, we need to compile the Scala code using scalac filename.scala
before executing it using scala filename
. But when I tried like scala filename.scala
, it runs and got the output.
Why is it so? So compiling using scalac is not required to run the code? Could someone please explain this.
Thanks.
scala -help
was really helpful. It says
A file argument will be run as a scala script unless it contains only
self-contained compilation units (classes and objects) and exactly one
runnable main method. In that case the file will be compiled and the
main method invoked. This provides a bridge between scripts and standard
scala source.
Thanks Dennis for the pointer.
Upvotes: 2
Views: 1122
Reputation: 2665
This behavior is explained in the help for the scala
command.
You can get the help by executing the scala -help
command.
Upvotes: 2
Reputation: 824
running the scala
command actually compiles it first behind the scenes, then runs the resulting program.
Upvotes: 5