如果我举一个我正在尝试做的例子可能会更好。说我有这样的事情:
def foo(a: String, b: String, c: String) = ...
object Bar {
val a = "a"
val b = "b"
val c = "c"
def fooArgs = a, b, c // not possible but it's shows what I'm trying to do
}
执行此操作会太多*(请记住,我无法更改foo
的定义方式)
foo(Bar.a, Bar.b, Bar.c)
我想知道是否可以做这样的事情:
foo(Bar.fooArgs)
如何使用scala执行此操作?
答案 0 :(得分:2)
def foo(a: String, b: String, c: String) = 0
object Bar {
val fooArgs = ("a", "b", "c")
}
foo.tupled(Bar.fooArgs)