Reputation: 5763
def main(args: Array[String]) {
foo("hello")
}
def foo(args:Any*){
bar(args)
}
def bar(args:Any *){
println(args)
}
Look the code above, the output is WrappedArray(WrappedArray(hello))
The String 'hello' is wrapped twice, how to avoid this
Upvotes: 1
Views: 443
Reputation: 59994
In the invocation of bar
, write this:
bar(args: _*)
This tells the compiler to use the args in args
, which at this point is very similar to a Seq[T]
, and pass each of them separately to bar
, instead of considering args
as the first of the repeated parameters that bar
accepts.
Upvotes: 5