Here’s the bit of code I have now, I am referencing any subclass of an Akka Actor called Processor:
def newProcessorProps(processorClass: Class[_ <: Processor]): Props = {
Props(new processorClass).withDispatcher("dispatcher")
}
I just can’t figure out how to instantiate a new class using that parameter. I don’t think reflection isn’t required here since I already have the class. Thanks for your help.
If you have the class object as a value you can instantiate by calling the
newInstance()method on it. So you’d do:You can also use the Manifest of a type to instantiate an object of that type
And then call it for a specific processor like this:
This only works as long as T has a parameterless constructor I think.