给出一些特征:
scala> sealed trait Foo
defined trait Foo
scala> sealed trait Parent
defined trait Parent
scala> case class Kid(name: String) extends Parent
defined class Kid
scala> sealed trait HasNickname
defined trait HasNickname
我尝试定义一个方法,它使A
满足:
Parent
HasNickname
Foo
但是我遇到了编译时错误:
scala> def f[A <: Parent : Foo with HasNickname](x: A): A = ???
<console>:14: error: Foo with HasNickname does not take type parameters
def f[A <: Parent : Foo with HasNickname](x: A): A = ???
^
如何修改f
以符合上述条件?