`def` vs `val` vs `lazy val` evaluation in Scala
问题 Am I right understanding that def is evaluated every time it gets accessed lazy val is evaluated once it gets accessed val is evaluated once it gets into the execution scope? 回答1: Yes, though for the 3rd one I would say "when that statement is executed", because, for example: def foo() { new { val a: Any = sys.error("b is " + b) val b: Any = sys.error("a is " + a) } } This gives "b is null" . b is never evaluated and its error is never thrown. But it is in scope as soon as control enters the