【发布时间】:2015-08-17 12:43:31
【问题描述】:
我正在尝试在一个辅助项目中使用 Scala + Play 2.4.2,我正在编写一个 json 解析器,而 IntelliJ 建议对我的语法进行此修复。
我不明白这是什么意思
对我来说,这个(Person.apply, _) 应该写成(Person.apply _),但是这样我得到一个cannot resolve symbol apply 并且代码无法编译。
既然我有一个重载的构造函数,(Person.apply _) 不应该用来自valuereads 函数的参数调用它吗?
package models
import play.api.libs.json._
import play.api.libs.functional.syntax._
case class Person(id: Long = 0, name: String, age: Int){
def this(name: String, age: Int) = this(0, name, age)
}
object Person {
implicit val personFormat = Json.format[Person]
implicit val valuereads = (__ \ "value").read {(
(__ \ "name").read[String] and
(__ \ "age").read[Int]
)(Person.apply, _) //**<=== THIS, what apply, _ stands for**
def apply(name: String, age: Int) = new Person(name, age)
}
固定语法仍然无法编译,但我没有收到任何警告。我在这里做错了什么?
顺便说一句,我正在关注此信息:https://www.playframework.com/documentation/2.4.x/ScalaJsonCombinators
【问题讨论】:
标签: scala intellij-idea playframework playframework-2.0