Imagine a class A that is abstract and has a set of case classes. We don't know how many set classes are or even the name those case classes have.
abstract class A(field: String)
//Example of a case class that extends A
case class B(f: String) extends A(f)
Now I have this:
a match {
case B(f) => println("f")
}
And I want to pass the case class type by an argument into a method. The reason I want this is because I will configure a set of rules in a file. And I want to load those rules and use pattern matching with some info those rules provide. I want to do something like this:
def printer (a: A, B: A) = {
a match{
case B(f) => println("f")
}
}
Is this possible?
If it isn't that easy can I use an abstract class in pattern matching? It would be perfect if I could simply use the abstract class since it has the main structure of all case classes.
EDIT:
Forgot to mention that case classes can have different arguments so it would be good to use something based on class A (since I can do my pattern matching with the field only)