Scala Specifying Function Parameter Names

Scala 函数Scala Functions

Normally, function call arguments are passed one by one in the order of the parameters defined in the function. However, we can also specify the function parameter names and pass arguments to the function without following the order. Example:

object Test {
   def main(args: Array[String]) {
        printInt(b=5, a=7);
   }
   def printInt( a:Int, b:Int ) = {
      println("Value of a : " + a );
      println("Value of b : " + b );
   }
}

Executing the above code produces the following output:

$ scalac Test.scala
$ scala Test
Value of a :  7
Value of b :  5

Scala 函数Scala Functions

Other Extensions