0

我正在使用 Scala & Play 2.5。我被这个错误困住了:

Game.scala:99: overloaded method value apply with alternatives:
[error]   (block: => play.api.mvc.Result)play.api.mvc.Action[play.api.mvc.AnyContent] <and>
[error]   (block: play.api.mvc.Request[play.api.mvc.AnyContent] => play.api.mvc.Result)play.api.mvc.Action[play.api.mvc.AnyContent] <and>
[error]   [A](bodyParser: play.api.mvc.BodyParser[A])(block: play.api.mvc.Request[A] => play.api.mvc.Result)play.api.mvc.Action[A]
[error]  cannot be applied to (Object)
[error]     def start(id: String, apiKey: Option[String]) = Action {

这是功能:

def start(id: String, apiKey: Option[String]) = Action {
  apiKey match {
    case Some(API_KEY) => {
      Server.actor ! Server.Start(id)
      Ok("Started")
    }
    case _ => Future.successful(Unauthorized)
  }
}
4

1 回答 1

3

问题是,该match语句的结果已被推断为Object,因为从一个 case 语句中您正在返回Result,而从另一个 case 语句中您正在返回Future[Result],所以唯一常见的超类型是Object. 要修复,请更改case _ => Future.successful(Unauthorized)case _ => Unauthorized.

于 2016-03-18T05:48:32.790 回答