In scala can I pass repeated parameters to other methods?

Posted by Fred Haslam on Stack Overflow See other posts from Stack Overflow or by Fred Haslam
Published on 2010-05-14T16:46:43Z Indexed on 2010/05/15 5:24 UTC
Read the original article Hit count: 178

Filed under:
|
|
|

Here is something I can do in java, take the results of a repeated parameter and pass it to another method:

public void foo(String ... args){bar(args);}
public void bar(String ... args){System.out.println("count="+args.length);}

In scala it would look like this:

def foo(args:String*) = bar(args)
def bar(args:String*) = println("count="+args.length)

But this won't compile, the bar signature expects a series of individual strings, and the args passed in is some non-string structure.

For now I'm just passing around arrays. It would be very nice to use starred parameters. Is there some way to do it?

© Stack Overflow or respective owner

Related posts about scala

Related posts about methods