java 如何在 Javadoc 中引用同一个类的另一个方法?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/10897520/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to reference another method of the same class in Javadoc?
提问by James Raitsev
Suppose your class has 2 methods:
假设你的类有 2 个方法:
contains() and
containsSame()
The distinction between them is subtle and you'd like to mention it as part of Javadoc
它们之间的区别很微妙,您想将其作为 Javadoc 的一部分提及
In Javadoc, how can you reference a method in the same class, by name?
在 Javadoc 中,如何通过名称引用同一个类中的方法?
回答by Pa?lo Ebermann
Use the @link
inline tag, and refer to the method with a leading #
.
使用@link
inline 标签,并引用带有前导的方法#
。
/**
* ...
* This method is similar to {@link #contains()}, with the following differences:
* ...
*/
public boolean containsSame();
/**
* This method does ...
*/
public boolean contains();
This example only works if there is actually a contains()
method which has no arguments (which, actually, seems to be not that useful). If you have only a contains
method with arguments, then either write the argument types in the parentheses:
这个例子只有在实际上有一个contains()
没有参数的方法时才有效(实际上,这似乎没有那么有用)。如果你只有一个contains
带参数的方法,那么要么在括号中写下参数类型:
/**
* ...
* This method is similar to {@link #contains(Element)}, with the following differences:
* ...
*/
public boolean containsSame(Element e);
/**
* This method does ...
*/
public boolean contains(Element e);
Or you can omit the parentheses at all:
或者您可以完全省略括号:
/**
* ...
* This method is similar to {@link #contains}, with the following differences:
* ...
*/
public boolean containsSame(Element e);
/**
* This method does ...
*/
public boolean contains(Element e);
If you have several methods named contains
(with different parameter lists), this version can't decide which one to use (the link will jump to any of them, hopefully they are all together and do similar things).
如果您有多个命名的方法contains
(具有不同的参数列表),则此版本无法决定使用哪个(链接将跳转到其中任何一个,希望它们都在一起并做类似的事情)。