Created
April 3, 2011 20:08
-
-
Save seanparsons/900724 to your computer and use it in GitHub Desktop.
Difference between call by name and normal parameters in Scala.
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 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