使用Akka java API时Kotlintypes推理编译错误

我想在Kotlin程序中使用Akka java API。 当我想为akka设置onComplete回调Future ,我遇到了Kotlin编译器错误,而java等价的工作很好:

 val future: Future = ask(sender, MyActor.Greeting("Saeed"), 5000) future.onComplete(object : OnComplete() { override fun onComplete(failure: Throwable?, success: Object?) { throw UnsupportedOperationException() } }, context.dispatcher()) 

java代码:

 Future future = ask(sender(), new MyActor.Greeting("Saeed"), 5000); future.onComplete(new OnComplete() { public void onComplete(Throwable failure, Object result) { if (failure != null) { System.out.println("We got a failure, handle it here"); } else { System.out.println("result = "+(String) result); } } },context().dispatcher()); 

Kotlin编译器错误:

 Error:(47, 24) Kotlin: Type inference failed: fun  onComplete(p0: scala.Function1<scala.util.Try!, U!>!, p1: scala.concurrent.ExecutionContext!): kotlin.Unit cannot be applied to (,scala.concurrent.ExecutionContextExecutor!) Error:(47, 35) Kotlin: Type mismatch: inferred type is  but scala.Function1<scala.util.Try!, scala.runtime.BoxedUnit!>! was expected 

我把这个项目推给了github 。

One Solution collect form web for “使用Akka java API时Kotlintypes推理编译错误”

那么,错误信息可能有点不清楚,因为很多Scala的东西和 ,但它明确定义的错误点:你的函数应该接受一个Any ,而不是一个Object 。 以下代码编译没有任何问题:

 val future: Future = ask(sender, MyActor.Greeting("Saeed"), 5000) future.onComplete(object : OnComplete() { override fun onComplete(failure: Throwable?, success: Any?) { throw UnsupportedOperationException() } }, context.dispatcher()) 
  • Kotlin拓展函数的多态性
  • 返回内部类的调用对象函数
  • Kotlin将TimeStamp转换为DateTime
  • 如何在Android Studio中更新Kotlin.Runtime
  • FirebaseListAdapter忽略orderByChild()和equalTo()
  • 如何保存参数名称进行调试?
  • 构造函数中的调用顺序是有保证的
  • Android / Kotlin:未解决的参考:木材
  • Kotlin - 如何正确连接字符串
  • 如何简化kotlin函数的默认实现
  • .class文件在哪里?
  • Kotlin language will be the best programming language for Android.