Scala type restrictions in type constructor

Can someone explain why the following does not compile? I want to be BB[A]also List[A]. The body of the method only provides this representation.

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]}
                                             ^
+5
source share
1 answer

I think you need to specify the _ parameter.

scala> def x[A, BB[X] <: List[X]](p: BB[A]) {p: List[A]}

work.

+9
source

All Articles