How to skip optional parameters in Scala?

前端 未结 3 1584
[愿得一人]
[愿得一人] 2021-02-19 03:30

Given the following function with optional parameters:

def foo(a:Int = 1, b:Int = 2, c:Int = 3) ...

I want to keep the default value of a

3条回答
  •  萌比男神i
    2021-02-19 03:57

    There's no way to skip the parameters, but you can use named parameters when you call your foo method, for example:

    // Call foo with b = 5, c = 7 and the default value for a
    foo(b = 5, c = 7)
    

    edit - You asked specifically how to do this by positional assignment: this is not possible in Scala.

提交回复
热议问题