A closure is a function, whose return value depends on the value of one or more variables declared outside this function.
A closure also works as a variable.
Example 1:
val multiplier = (i:Int) => i * 10
Example 2:
var factor = 3
val multiplier = (i:Int) => i * factor
Example 3:
object Hello {
def main(args: Array[String]) {
println( "multiplier(1) value = " + processme(1) )
println( "multiplier(2) value = " + processme(2) )
}
var factor = 4
val processme = (i:Int) => i * (factor+1)
}
Taking you to the next exercise in seconds...
Want to create exercises like this yourself? Click here.
No hints are availble for this assesment
Answer is not availble for this assesment
Please login to comment
0 Comments
There are 22 new comments.