I've been thinking of scala objects as simply shorthand for singleton java objects - that is, I'd expect them to behave like objects with guaranteed singleton instantiation. Then I run into something like this, which I don't understand:
object Test extends App{
var x ="a"
override def main(args:Array[String]):Unit = {
println(x )
}
}
which prints null rather than "a".
Looking at the generated classes, I get a Test$.class which is the object definition; however the instance value "a" is defined in a companion Test class using a generated delayedInit. Can someone shed some light on how this is instantiated? Clearly the mental model I had of this is incorrect.