Scaladoc [用例]
为什么 Scaladoc 中的某些方法描述以 [use case]
开头?
示例: scala.collection.immutable.StringOps.++
它只是一个将来要替换的占位符吗?
Why do some method descriptions in Scaladoc start with [use case]
?
Example: scala.collection.immutable.StringOps.++
Is it just a placeholder to be replaced in the future?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
它们是如何调用这些方法的简化示例。通常这些方法(
++
、map
、flatMap
等)包含一个隐式参数,最常见的是一个称为构建器工厂的参数,它(简而言之)抽象了结果集合的创建。在大多数情况下,集合的客户端不会指定这些隐式参数,因此 ScalaDoc 允许定义方法的简化描述 - 用例。这使用户能够快速了解相关方法背后的想法,而不必担心
CanBuildFrom
的含义及其使用方式。例如,这是
++
的完整声明:在大多数情况下,目标集合类型与调用的接收者相同,因此调用看起来就像声明如下(假设
++
是在List
上定义的):上面,隐式在编译时被解析,并且类型参数被推断。在大多数情况下,这应该是客户对该方法的看法。
如果您想用用例注释您自己的方法,请在文档注释中使用
@usecase
标记:They are simplified examples of how these methods are called. Usually these methods (
++
,map
,flatMap
, etc.) contain an implicit parameter, most often an argument called a builder factory which (simply put) abstracts creation of resulting collections.In most cases, a client of a collection does not specify these implicit parameters, so ScalaDoc allows defining a simplified description of the method - a use case. This enables users to quickly pick up the idea behind the method in question, and not be bothered with what e.g.
CanBuildFrom
means and how it's used.For example, this is the full declaration of
++
:In most cases, the target collection type is the same as the receiver of the call, so the call pretty much looks as if the declaration is the following (assuming
++
is defined on a, say,List
):Above, the implicit is resolved at compile time, and the type parameters are inferred. In most cases, this should be the client's view of the method.
And if you want to annotate your own method with use cases, use the
@usecase
tag in your doc comments: