Scala Functions - Default Parameter Values
Scala allows you to specify default parameter values for function parameters. When using default parameters, you don't need to pass arguments when calling the function; in this case, the function will use its default parameter values. If arguments are passed, the passed values will replace the default values. Example:
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
}
}
Executing the above code produces the following output:
$ scalac Test.scala $ scala Test 返回值 : 12Other Extensions
Scala Functions