score:11

Accepted answer

this happens because of how you used the app trait. the app trait uses the delayedinit feature which changes how the class body (including field initialization) is executed. the app trait includes a main method which executes the class body after binding the args field to the arguments to the program. since you have overridden main this initialization is not happening. you should not provide a main method when using the app trait. you should either put the application code directly in the class body or not inherit from the app trait.

score:1

try

lazy val x = "hello world"

that should give you the results you're expecting.

score:1

you are not support to have a main method on an object extending app. if you do override it, you'd better understand how, exactly, delayedinit works. in particular, objects extending app do not have static initialization -- that's the whole point of app.


Related Query

More Query from same tag