Fork me on GitHub

Graceless Failures

Tips, tricks, missteps, and minor revelations on the path to Scala wisdom.

lazy val

If you want a field or local variable to be initialized only when it’s required (that is, accessed/used for the first time), you want a lazy val.

Details and debate on this feature’s implementation can be found on the Scala User mailing list, but perhaps a better resource is this post that preceded the feature’s release from a developer at EPFL (Scala’s home).