7

My IDE's tooling shows that xs has type Int* in the following snippet:

def accept(xs: Int*) = true

The language reference, however, says that a repeated parameter declared as T* has type Seq[T]. Is there a difference between Int* and Seq[Int]?

Jean-Philippe Pellet
  • 59,296
  • 21
  • 173
  • 234

2 Answers2

8

They are different, and it's somewhere between bug and regrettable feature that T* leaks into type signatures.

Repeated parameter typed as T* rather than Seq[T]

psp
  • 12,138
  • 1
  • 41
  • 51
  • 1
    Assuming there was no concern about breaking existing code, what would the spec say about the type of the repeated parameters outside the method? Is it known or is it a matter of debate too? I feel the return type in `def f(t: T*) = t` should be `Seq[T]`. – huynhjl Apr 13 '11 at 09:12
  • 2
    It should unquestionably be Seq[T]. – psp Apr 13 '11 at 18:59
2

Yes, they are different. See, e.g., Overriding a repeated class parameter in Scala?

Community
  • 1
  • 1
Alexey Romanov
  • 167,066
  • 35
  • 309
  • 487