Created
November 8, 2010 22:51
-
-
Save maiha/668422 to your computer and use it in GitHub Desktop.
It's safe to use lazy val rather than val
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
| class Bar1 { | |
| lazy val a = "a" | |
| lazy val b = a + "b" | |
| } | |
| class Bar2 extends Bar1 { | |
| override lazy val a = "A" | |
| } | |
| (new Bar1).b // ab | |
| (new Bar2).b // Ab |
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
| class Foo1 { | |
| val a = "a" | |
| val b = a + "b" | |
| } | |
| class Foo2 extends Foo1 { | |
| override val a = "A" | |
| } | |
| (new Foo1).b // ab | |
| (new Foo2).b // nullb | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment