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
In the invocation of
bar, write this:This tells the compiler to use the args in
args, which at this point is very similar to aSeq[T], and pass each of them separately tobar, instead of consideringargsas the first of the repeated parameters thatbaraccepts.