You do not override the main method.
Since the App extends DelayedInit compiler overwrites your code as follows:
// Before: object Test extends App { println("test") } // After: object Test extends App { delayedInit{println("test")} }
From the DelayedInit documentation :
Classes and objects (but note, not traits) inheriting The DelayedInit marker DelayedInit will have its initialization code rewritten as follows: code becomes delayedInit(code) .
App trait implements DelayedInit as follows:
override def delayedInit(body: => Unit) { initCode += (() => body) }
So, in Test code of the constructor for println("test") is stored as a function ( () => Unit ) in the initCode field.
main App method is implemented as a call to all functions stored in the initCode field:
for (proc <- initCode) proc()
senia
source share