Created
April 15, 2017 07:53
-
-
Save tilakpatidar/7aba703d82c1d0ec185a02691b170ceb to your computer and use it in GitHub Desktop.
From http://stackoverflow.com/questions/7484928/what-does-a-lazy-val-do
Example of how lazy val does memoization.
Values are evaluated on first call only.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
val x = { println("x"); 15 } | |
//x | |
//x: Int = 15 | |
lazy val y = { println("y"); 13 } | |
//y: Int = <lazy> | |
x | |
//res2: Int = 15 | |
y | |
//y | |
//res3: Int = 13 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment