sof
sof

Reputation: 9649

Scala doesn't run as expected

The entry point of some.scala is defined below:

object MyApp extends App {
  println("Hello, World!")
} 
  1. If I run

    $ scala some.scala
    

    Scala quits quietly, then compile it via,

    $ scalac some.scala
    ...
    MyApp.class
    MyApp$delayedInit$body.class
    ...
    
  2. If I then run

    $ scala MyApp
    

    it works.

Does the delayedInit class above prevent case 1 from running?

Upvotes: 0

Views: 102

Answers (1)

Victor Moroz
Victor Moroz

Reputation: 9225

From scala man page:

If -howtorun: is left as the default (guess), then the scala command will check whether a file of the specified name exists. If it does, then it will treat it as a script file ...

So in your case scala is processing some.scala as a script file, not much different from typing it in REPL. It will define the object MyApp but won't execute it. Try to put a single line in some.scala:

println("Hello, World!")

and run it as scala some.scala

Upvotes: 1

Related Questions