Are there any examples for Akka's parametric Creators?
I have similar executors and want to combine their generated methods. I find this example in the akka docs but don't know how to fabricate my actor
static class ParametricCreator<T extends MyActor> implements Creator<T> {
@Override public T create() {
// ... fabricate actor here
}
}
then i try to do this to send test sender as parameters
private static Creator<MyActor> myCreator = MyActor::new;
public static Props props() {
return Props.create(myCreator);
}
but catch this
java.lang.ExceptionInInitializerError
at core.AppContext.initActors(AppContext.java:28)
at Main.main(Main.java:15)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:497)
at com.intellij.rt.execution.application.AppMain.main(AppMain.java:140)
Caused by: java.lang.IllegalArgumentException: erased Author types are not supported, use Props.create (actorClass, creator) instead
Sorry for my noob question and bad language, but I can't seem to fix this without some help.
+3
source to share
1 answer
I faced the same problem. Quite late, but perhaps helping others. The solution is in the error message: use Props.create (actorClass, creator) instead .
So:
private static Creator<MyActor> myCreator = MyActor::new;
public static Props props() {
return Props.create(MyActor.class, myCreator);
}
You must specify the exact type of actor in the creator.
+2
source to share