The problem is that the .toArray method returns an array of some type B , which is a superclass of T in List[T] . This allows you to use list.toArray on List[Bar] where Array[Foo] is required if Bar extends Foo .
Yes, the real reason this doesn't work is because the compiler is trying to figure out which B use, as well as how to get to IndexedSeq . It looks like it is trying to resolve the IndexedSeq[String] requirement, but B only guaranteed to String or the superclass from String ; hence a mistake.
This is my favorite job:
def fromList(list: List[String]): Foo = new Foo(list.toArray[String])
source share