Created
February 19, 2014 15:46
-
-
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.
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
> 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 |
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
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