Scala: How can I match only the first two elements of an arbitrary List
问题 I'm attempting to match a lists first two elements, however, it wont accept lists of arbitrary length. The below code fails. def demoCases() = { def actor1 = new Actor[Employee] {} def actor2 = new Actor[Employee] {} def actor3 = new Actor[Animal] {} var actors = List(actor1, actor2, actor3); println(); actors match { case (_: Employee) :: (_: Employee) :: tail => {println("nice 2 employees to start with ")}; case Nil => {println("no match")} } The exception : Exception in thread "main" scala