Skip to content

Instantly share code, notes, and snippets.

@seanparsons
Created April 3, 2011 20:08
Show Gist options
  • Save seanparsons/900724 to your computer and use it in GitHub Desktop.
Save seanparsons/900724 to your computer and use it in GitHub Desktop.
Difference between call by name and normal parameters in Scala.
val counter = new java.util.concurrent.atomic.AtomicInteger(0)
def printTwiceExpression(expression: => Int) = {
println(expression)
println(expression)
}
def printTwiceValue(value: Int) = {
println(value)
println(value)
}
printTwiceExpression(counter.incrementAndGet())
printTwiceValue(counter.incrementAndGet())
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment