A closure is a function which uses one or more variables declared outside this function.
// Scala - Closures
/* codebind.com */
import java.util.Date
object Demo {
val number = 10;
val add = (x : Int) => {
x + number;
}
def main(args: Array[String]) {
println(add(20));
println(number)
}
}
Leave a Reply