Latest web development tutorials

Scala function - default parameter values

Scala function Scala function

Scala can be specified as a function of the parameter default parameter values, using the default parameters, you call the function in the process may not need to pass parameters, then the function will call it the default parameter values, if you pass a parameter value is passed substituted Defaults. Examples are as follows:

object Test {
   def main(args: Array[String]) {
        println( "返回值 : " + addInt() );
   }
   def addInt( a:Int=5, b:Int=7 ) : Int = {
      var sum:Int = 0
      sum = a + b

      return sum
   }
}

Implementation of the above code, the output is:

$ scalac Test.scala
$ scala Test
返回值 : 12

Scala function Scala function