Skip to content

Instantly share code, notes, and snippets.

@Blaisorblade
Created February 19, 2014 15:46
Show Gist options
  • Save Blaisorblade/9094717 to your computer and use it in GitHub Desktop.
Save Blaisorblade/9094717 to your computer and use it in GitHub Desktop.
Show that DelayedInit.delayedInit is called multiple times, once for each class in the hierarchy which inherits (directy or indirectly) from delayedInit.
> console
[info] Starting scala interpreter...
[info]
Welcome to Scala version 2.10.3 (Java HotSpot(TM) 64-Bit Server VM, Java 1.7.0_51).
Type in expressions to have them evaluated.
Type :help for more information.
scala> new B
delayedInit START
A's constructor!
delayedInit END
delayedInit START
B's constructor!
delayedInit END
res0: B = B@36a70752
class A extends DelayedInit {
def delayedInit(body: => Unit) {
println("delayedInit START")
body
println("delayedInit END")
}
println("A's constructor!")
}
class B extends A {
println("B's constructor!")
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment