Scala specifies the function parameter name


Release date:2023-11-16 Update date:2023-11-16 Editor:admin View counts:182

Label:

Scala specifies the function parameter name

In general, the function call parameters are passed one by one according to the order of the parameters when the function is defined. However, we can also specify the parameter name of the function, and we do not need to pass the parameters to the function sequentially, as an 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 );
   }
}

Execute the above code, and the output is as follows:

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

Powered by TorCMS (https://github.com/bukun/TorCMS).