I consider refactoring few method signatures that currently take parameter of type List or Set of concrete classes —List[Foo]— to use repeated parameters instead: Foo*.
Update: Following reasoning is flawed, move along…
This would allow me to use the same method name and overload it based on the parameter type. This was not possible usingListorSet, becauseList[Foo]andList[Bar]have same type after erasure:List[Object].
In my case the refactored methods work fine with scala.Seq[Foo] that results from the repeated parameter. I would have to change all the invocations and add a sequence argument type annotation to all collection parameters: baz.doStuffWith(foos:_*).
Given that switching from collection parameter to repeated parameter is semantically equivalent, does this change have some performance impact that I should be aware of?
Is the answer same for scala 2.7._ and 2.8?
When Scala is calling a Scala varargs method, the method will receive an object that extends
Seq. When the call is made with: _*, the object will be passed as is*, without copying. Here are examples of this:Note
Arrayis passed as aWrappedArray. There’s no copying of elements involved, however, and changes to theWrappedArraywill be reflected in theArray.