我使用case类创建了一些用于在scala中喷涂的json消息.例如:
case class Foo(name: String, attrs: List[String])
implicit val fooFormat = jsonFormat2(Foo)
object Foo {
case class Invalid(error: String)
}
case class Bar(name: String, kv: Map[String, String])
implicit val barFormat = jsonFormat2(Bar)
Run Code Online (Sandbox Code Playgroud)
在上面的代码片段中,barFormat编译但fooFormat不是:
type mismatch; found : Foo.type required: (?, ?) => ?
Note: implicit value barFormat is not applicable here because it comes
after the application point and it lacks an explicit result type
Run Code Online (Sandbox Code Playgroud)
我不想barFormat代替使用fooFormat,并且我理解case类自动生成一个伴随对象,但是我不明白为什么这里有编译器错误,并且我很难解释错误消息.有谁知道这里的问题是什么以及如何解决它,最好不要删除我的Foo伴侣对象?
| 归档时间: |
|
| 查看次数: |
3028 次 |
| 最近记录: |