Created
November 21, 2014 13:15
-
-
Save lanceon/c658680b947ffbf860b0 to your computer and use it in GitHub Desktop.
Scala objects construction order
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
trait A { | |
println("constructing A") | |
val a = { | |
val x = value | |
println(s"calculating A.a = $x") | |
x | |
} | |
def value = { | |
println("A.value called") | |
0 | |
} | |
def get = { | |
val x = a | |
println(s"get called = $x") | |
x | |
} | |
} | |
class B extends A { | |
println("constructing class B") | |
val default = { | |
println("calculating 'default' = 1") | |
1 | |
} | |
override def value: Int = { | |
val x = default | |
println(s"B.value called = $x") | |
x | |
} | |
} | |
new B().get |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
http://puu.sh/cYVJ1/fb2c21a6db.png