You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
def main(args: Array[String]): Unit = {
SomeCode.First
}
}
{code}
It prints: {code}begin object init
null
initializing First{code}
But if we change First object to this one: {code}object First extends SomeCode(id = "First", "test") {println("initializing First")}{code}
Then the output will be: {code}initializing First{code}
It is ok behavior and I don't understand something, or it is a bug?
The text was updated successfully, but these errors were encountered:
I've found a strange behavior, explained it here: http://stackoverflow.com/questions/39569936/scala-object-initialization-bug
Here is the small example
{code}sealed case class SomeCode(
id: String,
legend: String = "sadsa")
object SomeCode {
println("begin object init")
object First extends SomeCode(id = "First") {println("initializing First")}
object Second extends SomeCode(id = "Second") {println("initializing Second")}
println(SomeCode.First)
}
object Main {
def main(args: Array[String]): Unit = {
SomeCode.First
}
}
{code}
It prints: {code}begin object init
null
initializing First{code}
But if we change First object to this one: {code}object First extends SomeCode(id = "First", "test") {println("initializing First")}{code}
Then the output will be: {code}initializing First{code}
It is ok behavior and I don't understand something, or it is a bug?
The text was updated successfully, but these errors were encountered: