akka onComplete似乎不起作用.尝试强制转换时java.lang.ClassCastException

mue*_*air 1 casting scala classcastexception akka

我目前试着问一个演员并在事后做"onComplete".

这是我的例子:

(此代码段包含在方法中)

(receivingActor ? message).mapTo[ReturnMessage].onComplete {
  case Success(rm) =>
    rm.getEitherObjectOrError() match {
      case Left(a) => return a
      case Right(e) =>
        sender ! ReturnMessage(None, Some(e))
        context.stop(self)
    }
  case Failure ... (doesnt matter)
}
Run Code Online (Sandbox Code Playgroud)

当我尝试将我的任何对象转换为期望的类型时......

any.asInstanceOf[ExpectedType]
Run Code Online (Sandbox Code Playgroud)

...我收到以下异常:

 ERROR akka.actor.OneForOneStrategy - scala.runtime.BoxedUnit cannot be cast to ExpectedType
 java.lang.ClassCastException: scala.runtime.BoxedUnit cannot be cast to ExpectedType
Run Code Online (Sandbox Code Playgroud)

通常我会期待任何类型为"任何"的对象,所以...我错过了什么?

提前致谢

vpt*_*ron 5

Future.onComplete有一个返回类型Unit,基本上它不返回任何东西.