类型构造函数的类型边界中的下划线 [英] Underscores in type bounds on type constructors

查看:68
本文介绍了类型构造函数的类型边界中的下划线的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有人可以解释为什么以下不能编译吗?我希望 BB[A] 也是一个 List[A].方法主体仅强制执行此视图.

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]}
                                             ^

推荐答案

我认为您需要为 _ 参数命名.

I think you need to name the _ parameter.

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

有效.

这篇关于类型构造函数的类型边界中的下划线的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆