加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 综合聚焦 > 服务器 > 安全 > 正文

为什么scaladoc方法签名错误?

发布时间:2020-12-16 08:59:10 所属栏目:安全 来源:网络整理
导读:Scala API中有很多地方,特别是在集合中,方法签名是错误的. 例如,Map.flatMap的scaladoc签名表示 def flatMap[B](f: (A) ? GenTraversableOnce[B]): Map[B] 但实际的签名是 flatMap[B,That](f: ((A,B)) ? GenTraversableOnce[B]) (implicit bf: CanBuildFrom[
Scala API中有很多地方,特别是在集合中,方法签名是错误的.

例如,Map.flatMap的scaladoc签名表示

def flatMap[B](f: (A) ? GenTraversableOnce[B]): Map[B]

但实际的签名是

flatMap[B,That](f: ((A,B)) ? GenTraversableOnce[B])
    (implicit bf: CanBuildFrom[Map[A,B],B,That]): That

这个特别没有意义,因为scaladoc签名包含Map [B],但Map有两个类型参数,而不是一个.

这里发生了什么?这是一个错误吗?

解决方法

您在生成的文档中看到的错误签名称为“用例”.他们应该通过展示理想化的API来澄清文档,类似于真实的API,但省略了繁琐的细节(如普遍的隐式 CanBuildFrom参数 bothers some people).

对于具有用例的方法,您可以通过单击方法名称来显示该方法的详细信息,然后单击“完整签名”以展开显示签名的另一个部分,从而获得真实签名.

参考

> Scala issue SI-3448,创建于2010年5月,专门处理为Map显示的错误数量的类型参数.这个问题在2012年7月关闭“不会修复”.
> 2014年1月起,Paul Phillips的谈话Scala Collections: Why Not?在slide 1,slide 2,0006中将用例评为“谎言”.
>在GenTraversableLike.scala中,您可以看到一个导致生成用例文档的指令示例:

@usecase def flatMap[B](f: A => TraversableOnce[B]): $Coll[B]

类似的问题

> Why does the scaladoc say HashMap.toArray returns Array[A] instead of Array[(A,B)]?
> The List :: method and covariance … why do they hide the real signature?
> scaladoc for map on Map … is the documentation wrong,or am I missing something?
> What’s going on here with scala.collection.immutable.Stack.+: (prepend)? …
> Why do some method descriptions in Scaladoc start with [use case]?
> How to explain Map.map result

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读