问题
Can someone explain why the following doesn't compile? I want that BB[A]
is also a List[A]
. The method body only enforces this view.
scala> def x[A, BB[_] <: List[_]](p: BB[A]) {p: List[A]}
<console>:8: error: type mismatch;
found : BB[A]
required: List[A]
def x[A, BB[_] <: List[_]](p: BB[A]) {p: List[A]}
^
回答1:
I think you need to name the _ parameter.
scala> def x[A, BB[X] <: List[X]](p: BB[A]) {p: List[A]}
works.
来源:https://stackoverflow.com/questions/6492934/underscores-in-type-bounds-on-type-constructors