如何在javadoc中使用@value标签?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/19807696/
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 use @value tag in javadoc?
提问by Nikolay Kuznetsov
I am using a class with private constructor instead of an enum (this is a requirement). And now I am trying to add javadoc tags to document each public static final
entity.
我正在使用带有私有构造函数而不是枚举的类(这是必需的)。现在我正在尝试添加 javadoc 标签来记录每个public static final
实体。
1) What is prefered place to put javadoc tags: like ob1
or ob2
?
1) 什么是放置 javadoc 标签的首选位置:likeob1
或ob2
?
2) Both options generate error in IDEA
@value tag must reference field with a constant intializer.
2)两个选项在IDEA中都会产生错误
@value tag must reference field with a constant intializer.
/**
* {@value #ob1} object1 description
*/
public class MyClass {
public static final Object ob1 = new Object();
/**
* {@value #ob2} object2 description
*/
public static final Object ob2 = new Object();
private MyClass() {}
}
回答by JamesB
I don't think Kayaman's answer is sufficient as the question is how to use the @value tag in javadocs.
我认为 Kayaman 的回答不够充分,因为问题是如何在 javadocs 中使用 @value 标签。
I think the problem lies in the fact that the value of the field being referenced is not a literal value.
我认为问题在于被引用的字段的值不是文字值。
In eclipse, when you have
在日食中,当你有
/**
* {@value #ob2} object2 description
*/
public static final Object ob2 = new Object();
the generated Javadocs are {@value #ob2} object2 description. However, when you have
生成的 Javadoc 是{@value #ob2} object2 description。然而,当你有
/**
* {@value #ob2} object2 description
*/
public static final String ob2 = "hello";
the generated Javadocs are "hello" object2 description(the expected output).
生成的 Javadoc 是“hello”object2 描述(预期输出)。
So, in summary, you are using the @value tag correctly in the javadocs but the value will only be rendered correctly if the field has been initialised with a literal value.
因此,总而言之,您在 javadocs 中正确使用了 @value 标记,但只有在字段已使用文字值初始化时才能正确呈现该值。