Skip to content

Instantly share code, notes, and snippets.

@maiha
Created November 8, 2010 22:51
Show Gist options
  • Save maiha/668422 to your computer and use it in GitHub Desktop.
Save maiha/668422 to your computer and use it in GitHub Desktop.
It's safe to use lazy val rather than val
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
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