Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 667267
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T23:54:34+00:00 2026-05-13T23:54:34+00:00

I consider refactoring few method signatures that currently take parameter of type List or

  • 0

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 using List or Set, because List[Foo] and List[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?

  • 1 1 Answer
  • 1 View
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-13T23:54:34+00:00Added an answer on May 13, 2026 at 11:54 pm

    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:

    scala> object T {
         |   class X(val self: List[Int]) extends SeqProxy[Int]  {
         |     private val serial = X.newSerial
         |     override def toString = serial.toString+":"+super.toString
         |   }
         |   object X {
         |     def apply(l: List[Int]) = new X(l)
         |     private var serial = 0
         |     def newSerial = {
         |       serial += 1
         |       serial
         |     }
         |   }
         | }
    defined module T
    
    scala> new T.X(List(1,2,3))
    res0: T.X = 1:List(1, 2, 3)
    
    scala> new T.X(List(1,2,3))
    res1: T.X = 2:List(1, 2, 3)
    
    scala> def f(xs: Int*) = xs.toString
    f: (Int*)String
    
    scala> f(res0: _*)
    res3: String = 1:List(1, 2, 3)
    
    scala> f(res1: _*)
    res4: String = 2:List(1, 2, 3)
    
    scala> def f(xs: Int*): Seq[Int] = xs
    f: (Int*)Seq[Int]
    
    scala> def f(xs: Int*) = xs match {
         |   case ys: List[_] => println("List")
         |   case _ => println("Something else")
         | }
    f: (Int*)Unit
    
    scala> f(List(1,2,3): _*)
    List
    
    scala> f(res0: _*)
    Something else
    
    scala> import scala.collection.mutable.ArrayBuffer
    import scala.collection.mutable.ArrayBuffer
    
    scala> def f(xs: Int*) = xs match {
         |   case ys: List[_] => println("List")
         |   case zs: ArrayBuffer[_] => zs.asInstanceOf[ArrayBuffer[Int]] += 4; println("Array Buffer")
         |   case _ => println("Something else")
         | }
    f: (Int*)Unit
    
    scala> val ab = new ArrayBuffer[Int]()
    ab: scala.collection.mutable.ArrayBuffer[Int] = ArrayBuffer()
    
    scala> ab + 1
    res11: scala.collection.mutable.Buffer[Int] = ArrayBuffer(1)
    
    scala> ab + 2
    res12: scala.collection.mutable.Buffer[Int] = ArrayBuffer(1, 2)
    
    scala> ab + 3
    res13: scala.collection.mutable.Buffer[Int] = ArrayBuffer(1, 2, 3)
    
    scala> f(ab: _*)
    Array Buffer
    
    scala> ab
    res15: scala.collection.mutable.ArrayBuffer[Int] = ArrayBuffer(1, 2, 3, 4)
    

    Note

    • An Array is passed as a WrappedArray. There’s no copying of elements involved, however, and changes to the WrappedArray will be reflected in the Array.
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Consider that I've a excel sheet in below format: person age Foo 29 Bar
Consider a ViewModel and a View that uses it, where the DataContext is set
I have been tasked with refactoring a project that currently uses an EAV model
All the refactoring tools for C# and VB.Net that I have seen only consider
Suppose I have a list of items that are currently processed in a normal
Consider the scenario of refactoring and reorganizing a very large PHP project that contains
Consider this scenario. I have my own website, that I use as my identifier,
Consider this scenario. I have an object, lets call it.... Foo. Foo raises a
Is it possible to make resharper include linked files when refactoring? Consider a solution
Consider that you have System_A which is a web application. And System_A has simply

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.