Underscores in type bounds on type constructors

不打扰是莪最后的温柔 提交于 2020-01-13 09:17:47

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!