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

如何消除歧义的方法链接?

发布时间:2020-12-16 09:44:18 所属栏目:安全 来源:网络整理
导读:我正在使用 overloaded methods记录一个Scala类。当在scaladoc评论中提到Scala类时,我如何区分它们?例如,如果我有 /** * The most important method is [[Doc.foo]]. */object Doc { def foo[A]: A = throw new UnsupportedOperationException; def foo[A
我正在使用 overloaded methods记录一个Scala类。当在scaladoc评论中提到Scala类时,我如何区分它们?例如,如果我有

/**
 * The most important method is [[Doc.foo]].
 */
object Doc {
  def foo[A]: A = throw new UnsupportedOperationException;
  def foo[A,B >: A](x: A): B = x;
}

并运行sbt doc我得到

Doc.scala:1: warning: The link target “Doc.foo” is ambiguous. Several (possibly overloaded) members fit the target:

  • method foo[A,B>:A](x:A):B in object Doc [chosen]
  • method foo[A]:Nothing in object Doc

使用foo [A,B>:A]等链接不起作用。

解决方法

以下似乎在Scala 2.10中伎俩。

/**
 * The most important method is [[Doc.foo[A]:A*]].
 */

这里有一些提示scaladoc给了我:

[warn] Quick crash course on using Scaladoc links
[warn] ==========================================
[warn] Disambiguating terms and types: Prefix terms with '$' and types with '!' in case both names are in use:
[warn]  - [[scala.collection.immutable.List!.apply class List's apply method]] and
[warn]  - [[scala.collection.immutable.List$.apply object List's apply method]]
[warn] Disambiguating overloaded members: If a term is overloaded,you can indicate the first part of its signature followed by *:
[warn]  - [[[scala.collection.immutable.List$.fill[A](Int)(?A):List[A]* Fill with a single parameter]]]
[warn]  - [[[scala.collection.immutable.List$.fill[A](Int,Int)(?A):List[List[A]]* Fill with a two parameters]]]
[warn] Notes: 
[warn]  - you can use any number of matching square brackets to avoid interference with the signature
[warn]  - you can use . to escape dots in prefixes (don't forget to use * at the end to match the signature!)
[warn]  - you can use # to escape hashes,otherwise they will be considered as delimiters,like dots.

(编辑:李大同)

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

    推荐文章
      热点阅读