Skip to content

Instantly share code, notes, and snippets.

@andrewconner
Created October 23, 2015 18:24
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save andrewconner/932c743104659a0625e7 to your computer and use it in GitHub Desktop.
Save andrewconner/932c743104659a0625e7 to your computer and use it in GitHub Desktop.
class Parent {
val a = 1
val b = a
}
class Kid extends Parent {
override val a = 100
}
new Kid().b // == 0
new Kid().a // == 100
@andrewconner
Copy link
Author

Two easy solutions, depending on your needs:

class Parent {
  def a = 1
  lazy val b = a
}
class Parent {
  def a = 1
  def b = a
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment