Scala中有没有办法禁止使用函数的命名参数?
例:
def func(num: Int, power: Int) = math.pow(num, power)
func(3, 2) // OK
func(num = 3, power = 2) // Forbidden
Run Code Online (Sandbox Code Playgroud)
您可以使用函数文字:
val func = (num: Int, power: Int) => math.pow(num, power)
func(3, 2)
func(num = 3, power = 2) // "error: not found: value num"
Run Code Online (Sandbox Code Playgroud)
(虽然Function2的apply还是有争论的名字:)
func(v1 = 3, v2 = 2)
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
166 次 |
| 最近记录: |