Values & References12 / 16
Up next

lazy val

@main def main(): Unit =
  // a lazy val runs its body on first use, then caches
  lazy val once = { println("computing"); 42 }
  println("before")
  println(once)
  println(once)
What you're solving

computed once, then cached