I am new to scala with a java background.
Is there a way to pattern match super classes (or traits) in a class inheritance tree with leafs as case classes and nodes abstract classes or traits? As far as I know case class inheritance is not allowed.
I think that pattern matching abstract classes in large inheritance tree would be very helpful
In the following code the last case in the match statement errors during compilation
sealed trait Person {
def name: String
}
case class Customer(name: String, email: String) extends Person
sealed trait Employee extends Person {
def id: Int
}
case class Worker(name: String, id: Int, skills: Array[String]) extends Employee
case class Manager(name: String, id: Int, title: String) extends Employee
def process(p: Person) = p match {
case Customer(_, email) => email
case Employee(name, _) => name + "@acme.com"
}