Is there any examples for Akka parametric Creators?

时间:2015-06-30 13:46:55

标签: java java-8 akka

I have some similiar actors and want unify their generated methods. I find this example in akka docs but have not any idea how fabricate my actor

static class ParametricCreator<T extends MyActor> implements Creator<T> {
@Override public T create() {
  // ... fabricate actor here
}

}

then I try do this for test sending creator 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 Creator types are unsupported, use Props.create(actorClass, creator) instead

Sorry for my noob question and bad language but I can`t solve this problem without help.

1 个答案:

答案 0 :(得分:2)

我遇到了同样的问题。很晚但可能对别人有帮助。解决方案出现错误消息:使用Props.create(actorClass,creator)代替

所以:

private static Creator<MyActor> myCreator = MyActor::new;
public static Props props() {
    return Props.create(MyActor.class, myCreator);
}

您必须在创作者中指定演员的确切类型。