Trying to find a valid and flexible way to store a sequence of class types in Scala that I can later use to spin up new instances of that type:
class Event(
val name: String,
val channels: Seq[String],
val processors: Seq[T] // a sequence of processor classes
)
Each processor in the sequence above is an Akka Actor class. I plan on creating a new Actor every time data is received by mapping out the processors like so:
event.processors.foreach { processorType =>
val processor = newProcessor(processorType) // does all the Akka creation stuff
processor ! Data
}
Update: apparently the above is rather correct, so how do we enforce that Seq[T] is processor-types only? So sticking in classes like class Calculator extends Processor
My guess is that there are some gotchas with Scala that I missed, so thanks for your help.
Seq[T]would only be valid if there is either a typeTor a type parameter.To have a list of classes it has to be of a Seq[Class[_]].
Let’s suppose the processors you mention are of type
Processor. A smaller illustrative example: