scala> class A (s: String*) { val l: ListBuffer[String] = ListBuffer[String](s) }
<console>:8: error: type mismatch;
found : String*
required: String
class A(s: String*) {val l: ListBuffer[String] = ListBuffer[String](s)}
Why is it not possible to pass the argument s to the apply method of ListBuffer[String] which is
def apply[A](elems: A*): CC[A] = { ... }
(Method apply from the GenericCompanion.scala )
The code ListBuffer[String]("foo", "bar") does work. But it seems I can not pass through the argument list of strings from s which is also String*.
You need to tell Scala to unpack
s:You also don’t need the the explicit types: