Given a few traits:
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
I attempted to define a method that takes an A
that satisfies:
- sub-class of
Parent
- implements trait
HasNickname
- implements trait
Foo
But I got a compile-time error:
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 = ???
^
How can I modify f
to fit the above criteria?