Created
June 29, 2013 11:27
-
-
Save alextp/5890802 to your computer and use it in GitHub Desktop.
This file contains hidden or 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 Foo { | |
def a: String | |
val b = a + " " | |
} | |
class Bar extends Foo { override val a = "a" } | |
class Baz extends Foo { override def a = "a" } | |
class Bla extends Foo { override lazy val a = "a" } | |
// guess what the code below prints | |
println(new Bar().b) | |
println(new Baz().b) | |
println(new Bla().b) | |
trait Foo2 { | |
def a: String = "b" | |
val b = a + " " | |
} | |
class Bar2 extends Foo2 { override val a = "a" } | |
class Baz2 extends Foo2 { override def a = "a" } | |
class Bla2 extends Foo2 { override lazy val a = "a" } | |
// And for the kicker, guess what the code below prints | |
println(new Bar2().b) | |
println(new Baz2().b) | |
println(new Bla2().b) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment