Skip to content

Instantly share code, notes, and snippets.

@KirinDave
Forked from Ragmaanir/gist:1162677
Created August 22, 2011 15:53
Show Gist options
  • Save KirinDave/1162732 to your computer and use it in GitHub Desktop.
Save KirinDave/1162732 to your computer and use it in GitHub Desktop.
cyclic definitions
object A1 { lazy val X = B1.Y }
object B1 { lazy val Y: Int = A1.X }
println("Executes safely unless you try and evaluate A1.X or B1.Y because they have no definition.")
object ABase { val X = 1 }
object A2 { lazy val X = B2.Y+1 }
object B2 { lazy val Y :Int = ABase.X*2 }
println("Even this could cause problems, but lazy helps. A2.X = " + A2.X.toString)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment