Skip to content

Instantly share code, notes, and snippets.

@tilakpatidar
Created April 15, 2017 07:53
Show Gist options
  • Save tilakpatidar/7aba703d82c1d0ec185a02691b170ceb to your computer and use it in GitHub Desktop.
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.
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