I need a function to accept any case class which extends a trait. To give an example
Suppose there is a trait
trait Action {
def execute(param: Parameters)
}
And following parameters can be passed depending on what type of action it is
trait Parameters
case class A(x: String, y: Double) extends Parameters
case class B(x: Int, y:String, z: Double) extends Parameters
User should be able to specify what it wants as parameters
class Action1 extends Action {
override def execute(param: A)
}
class Action2 extends Action {
override def execute(param: B)
}
and while calling
def run(t: Action) {
t.execute(new A("a", 1.0))
}
How to achieve this? When I implement Action1, it says I will get error that we cannot override because trait says execute method accepts Parameters, but while overriding, we want a class which extends Parameters.