scala - When are singleton objects constructed? -


in

object o {   // construction code , member initialization } 

construct, when code going run?

the code called when o accessed first time (some method or property). example following program

object o {   println("hello o")   def dosome() {} }  object app extends application {   println("before o")   o.dosome()   println("after o") } 

will yield

before o hello o after o 

it's not enough define o. won't work to call class.forname("o") since compiled object's name o$, calling class.forname("o$") do.


Comments

Popular posts from this blog

javascript - Enclosure Memory Copies -

php - Replacing tags in braces, even nested tags, with regex -