如何引用文档中的实例方法?
编写文档时如何引用实例字段?
考虑以下代码:
object Foo {
val foo = 42
}
class Foo {
val foo = 42
}
在 Java 中,可以使用 Foo.foo
作为“静态”方法,使用 Foo#foo
作为实例方法。
但在 Scala 中 #
已经被用于路径相关类型并且
class Foo {
class foo
def foo = 42
}
是合法的代码,所以我不能明确地引用它。
有一些惯例吗?
How can I refer to an instance field when writing documentation?
Consider this code:
object Foo {
val foo = 42
}
class Foo {
val foo = 42
}
In Java, one would use Foo.foo
for the "static" method and Foo#foo
for the instance method.
But in Scala #
is already taken for path-dependent types and
class Foo {
class foo
def foo = 42
}
is legal code, so I can't refer to it unambiguously.
Is there some convention how this should look like?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
艰难的。也许类似于英语,如
Foo's foo
中那样?我错过了#
的歧义。不过,这仍然是我的首选,因为只有在没有上下文的情况下才存在歧义。当引用一种类型时,#
有一个含义。当引用一个值或方法时,#
有另一个值或方法。由于类型和方法/值不共享名称空间,因此我认为这里没有相关性。
Tough. Maybe English-like, as in
Foo's foo
? I had missed the ambiguity of#
. That is still my preferred choice, though, because the ambiguity only exists in the absence of context. When referring to a type,#
has one meaning. When referring to a value or method,#
has another.Since types and methods/values do not share the namespace, I don't see the ambiguity being of relevance here.