Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
是否可以从 Scala 中的可迭代对象中传递函数参数?
val arguments= List(1,2) def mysum(a:Int,b:Int)={a+b}
如何使用 List 内容作为参数调用 mysum?
要让它在列表上工作,您需要将该mysum函数容纳为“varargs”:
mysum
scala> def mysum ( args : Int* ) = args.sum mysum: (args: Int*)Int scala> val arguments = List(1,2) arguments: List[Int] = List(1, 2) scala> mysum(arguments: _*) res0: Int = 3