I have a case class that takes Seq [T] as a parameter:
case class MyClass(value: Seq[T])
Now i want to write
MyClass(t1,t2,t3)
So I defined
object MyClass {
def apply(value: T*) = new MyClass(value.toSeq)
}
This does not work because the case class defines
object MyClass {
def apply(value: Seq[T])
}
and Seq [T] and T * are of the same type after erasing, so I cannot overload them.
But I would like to allow both access paths. Both paths must be allowed:
MyClass(t1,t2,t3)
MyClass(some_seq_of_T)
Since Seq [T] and T * are almost of the same type (at least after erasing, and inside the function with the parameter T *, it becomes Seq [T]), I think there should be a way to resolve both ways of calling it.
Whether there is a?
source
share