I have the following code, where T
is a actor subclass that should also take a constructor argument:
abstract class AbstractActor(dest: ActorRef) extends Actor {
//...
}
class ChildActor(dest: ActorRef) extends AbstractActor(dest) {
//...
}
class ParentActor[T <: AbstractActor : ClassTag] extends Actor {
val childRef = context.actorOf(Props(classOf[T], destActorRef))
//...
}
The compiler gives the error: "class type required but T found". I assume the problem is that one could also define childActor without the constructor parameter:
class ChildActor extends AbstractActor(dest) {
//...
}
So, I tried:
class ParentActor[T <: AbstractActor : ClassTag] extends Actor {
def createT(dest: ActorRef)(implicit ev: Manifest[T]): ActorRef =
context.actorOf(Props(ev.runtimeClass, dest))
val childRef = createT(destActorRef)
//...
}
But then I get: "no manifest available for T". Any ideas on what I'm doing wrong? Thank you