【发布时间】:2020-10-17 08:27:00
【问题描述】:
对 scala 有点陌生,对这里的类型定义以及如何解决它有点困惑。
private def getContract(organizationId: String, sc: SecurityContext): Future[Contract] = {
val configRequest = ConfigsActor.ReadConfigRequest(CONFIG_KEY, Option(organizationId))(sc)
(configActor ? configRequest).mapTo[Config] andThen {
case Success(config) =>
JsonUtil.extract[Contract](config.data)
case otherwise =>
log.warning("some unknown case has happened", otherwise)
}
}
我希望 akka 请求返回结果,将其映射到 Config。在我的 andThen 子句中将其转换为 Contract 类型并返回。
但我得到一个类型不匹配
[error]
[error] found : scala.concurrent.Future[com.example.service.Config]
[error] required: scala.concurrent.Future[com.example.service.Contract]
[error] (configActor ? configRequest).mapTo[Config] andThen
[error]
【问题讨论】: