Scala – Closures




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)
  }
}


Partner Sites

VideoToGifs.com

EasyOnlineConverter.com

SqliteTutorials.com





Be the first to comment

Leave a Reply

Your email address will not be published.


*