Answer the question
In order to leave comments, you need to log in
How to concatenate sequences in a parameterized class?
I'm learning about polymorphism in Scala and can't figure out the following question.
For example, there is some class hierarchy:
class A
class B extends A
class C extends B
class Foo[T](a: Seq[T]) {
def push[T](b: Seq[T]): Foo[T] = {
new Foo(a ++ b) // тут получаю ошибку - type mismatch; found : Seq[Any]; required: Seq[T]
}
}
Seq[T]
Seq[Any]
val foo = new Foo(Seq(new C, new C))
val bar = foo.push(Seq(new B, new B))
println(bar) // должен содержать [C, C, B, B]
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question