I have a case class, taking a Seq[T] as parameter:
case class MyClass(value: Seq[T])
I now want to be able to write
MyClass(t1,t2,t3)
So I defined
object MyClass {
def apply(value: T*) = new MyClass(value.toSeq)
}
It doesn't work, because the case class defines
object MyClass {
def apply(value: Seq[T])
}
and Seq[T] and T* have the same type after erasure, so I can't overload them.
But I'd like to allow both access ways. Both ways should be allowed:
MyClass(t1,t2,t3)
MyClass(some_seq_of_T)
Since Seq[T] and T* are almost the same type (at least after erasure; and inside of the function having the parameter T* becomes Seq[T]), I think there should be a way to allow both ways of calling it.
Is there?
MyClass
has a type parameter? – Rogach