使用一些结构:
object Foo {
trait Bar[B]
}
trait Foo[A, B, F <: Foo[A, B, F]] {
def baz(fun: A => Foo.Bar[B] => Unit): Unit
}
...为什么存在类型会引起麻烦:
def test[A, F <: Foo[A, _, F]](foo: F) =
foo.baz { a => b => println(b) }
出现以下错误:
<console>:38: error: type mismatch;
found : A => Foo.Bar[(some other)_$1(in type F)] => Unit
forSome { type (some other)_$1(in type F) }
required: A => (Foo.Bar[_$1(in type F)] => Unit)
foo.baz { a => b => println(b) }
^
虽然以下编译:
def test[A, JamesClapperSociopath, F <: Foo[A, JamesClapperSociopath, F]](foo: F) =
foo.baz { a => b => println(b) }