0

我已经根据 Play Framework 文档站点http://www.playframework.com/documentation/2.1.1/ScalaJsonRequests中的示例实现了我的第一个 Play 2.1 控制器。我的代码的操作部分如下所示:

object Sessions extends Controller {
  val log = LoggerFactory.getLogger(getClass())

  implicit val rds = (
    (__ \ 'userName).read[String] and
    (__ \ 'credentials).read[String]) tupled

  def session = Action(parse.json) { request =>
    log.trace("session request: {}", request)
    request.body.validate[(String, String)].map {
      case (userName, credentials) =>
        if (isAuthenticated(userName, credentials)) {
          Created(createSession(userName))
        } else {
          log.warn("userName: {} failed isAuthenticated", userName)
          BadRequest
        }
    }.recoverTotal {
      e =>
        val message = "Parse error: " + JsError.toFlatJson(e)
        log.warn(message)
        BadRequest
    }
  }

问题是 Scala 编译器会警告“元组”的事情(这是一个关键字,运算符,我不知道......我是新手)。我不知道警告是否真实,我是否应该采取建议的措施。警告的文本​​是

[warn] /Users/bobk/work/dm2-server/app/controllers/admin/Sessions.scala:20: postfix operator tupled should be enabled
[warn] by making the implicit value language.postfixOps visible.
[warn] This can be achieved by adding the import clause 'import scala.language.postfixOps'
[warn] or by setting the compiler option -language:postfixOps.
[warn] See the Scala docs for value scala.language.postfixOps for a discussion
[warn] why the feature should be explicitly enabled.
[warn]     (__ \ 'credentials).read[String]) tupled
[warn]                                       ^
[warn] one warning found

在 ScalaDocs 中搜索关于“scala.language.postfixOps”的讨论一无所获;我找不到讨论。这个警告是什么意思?我应该采取建议的措施让它消失吗?

我有很多关于 Scala 和 Play 的知识要学习。

4

1 回答 1

2

当您使用更高级的功能时,会出现这些类型的警告。SIP 18: Modularizing Language Features更详细地解释了它。

在您的情况下,您可以这样做:

(__ \ 'credentials).read[String]).tupled

我建议确保您的代码中没有任何警告。您想要解决这些类型的警告的方式取决于您。我通常导入该功能。

于 2013-05-25T16:21:14.800 回答