I want to be able to assert the type of a parameterized List in Scala. For e.g. I have the following types:
class Animal
class Cat extends Animal
class Dog extends Animal
And I instantiate lists as follows:
val l1 = List(new Cat())
val l2 = List(new Dog())
val m = l1 ::: l2
When I try to assert the type of list m
using the scalatest
Matchers, I am only able to assert the generic type, not the parameterized type.
import org.scalatest.Matchers._
m shouldBe a [List[_]]
What I actually want to do is to assert that m
is of type List[Animal]
and NOT of type List[Cat]
or List[Dog]
Is there any way I can do that?