编译时:
object Test extends App {
implicit def pimp[V](xs: Seq[V]) = new {
def dummy(x: V) = x
}
}
我明白了:
$ fsc -d aoeu go.scala
go.scala:3: error: Parameter type in structural refinement may not refer to an abstract type defined outside that refinement
def dummy(x: V) = x
^
one error found
为什么?
(Scala: "Parameter type in structural refinement may not refer to an abstract type defined outside that refinement"并没有真正回答这个问题。)
答案 0 :(得分:22)
答案 1 :(得分:11)
发布后不久发现了这个问题:我必须定义一个命名类而不是使用匿名类。 (尽管如此,仍然希望听到对推理的更好解释。)
object Test extends App {
case class G[V](xs: Seq[V]) {
def dummy(x: V) = x
}
implicit def pimp[V](xs: Seq[V]) = G(xs)
}
作品。