Eclipse中的javadoc @value注释问题 [英] javadoc @value annotation issue in Eclipse
问题描述
我在这里读了很多书,但没有找到答案.我遇到了 @value
Javadoc注释的问题.
I've read a lot here but didn't find the answer. I faced a problem with a @value
Javadoc annotation.
IDE:Eclipse Oxygen.1a发行版(4.7.1a)
IDE: Eclipse Oxygen.1a Release (4.7.1a)
如果我将其放在String
变量上就可以正常工作,但是如果变量为Integer
则一切都不好.
If I place it on the String
variable it is ok and works properly, but if the variable is Integer
then everything is bad.
以下是其中变量并排放置的代码:
Here is a code where variables stand side by side:
/**
* Default delimiter. {@value #DEFAULT_LIST_SEPARATOR}
*/
public final static String DEFAULT_LIST_SEPARATOR = ",";
/**
* Default int value. {@value #START_VALUE}
*/
public final static Integer START_VALUE = 20000;
,第一个变量说明正确显示,而其他变量,我仅看到{@value #START_VALUE}
.
and for the first variable description shows properly, but for the other, I see only {@value #START_VALUE}
.
伙计们,我在哪里错了?
Where am I wrong, guys?
推荐答案
如果使用 Integer
而不是int
,则无法解析@value
.
在您的示例中,常量START_VALUE
是类型Integer
的对象,该对象包装了值20000
.所以问题是, @value
是否支持自动装箱??
In your example, the constant START_VALUE
is an object of the type Integer
which wraps the value 20000
. So the question is, does @value
support autoboxing? The Java Language Specification does not cover Javadoc comments. There seems to be no formal specification for Javadoc, just the following simple description for @value
which does not answer the question:
如果使用 Oracle Java SDK的Javadoc工具以事实上的标准生成HTML,则int
允许用于int
,但不允许用于键入Integer
. Oracle的Java 8和Java 9开发工具包的Javadoc工具报告了相同的错误:
If using the the Javadoc tool of the Oracle Java SDK to generate HTML as de facto standard, @value
is allowed for int
, but not for the type Integer
. The Javadoc tools of Oracle's Java 8 and Java 9 Development Kit report the same error:
error: value does not refer to a constant
* Default int value. {@value #START_VALUE}
^
如果使用{@value}
而不是{@value #START_VALUE}
,则错误变为error: {@value} not allowed here
.
If using {@value}
instead of {@value #START_VALUE}
the error becomes error: {@value} not allowed here
.
让我们看看以下情况:
public class JavadocValue {
/** STRING = {@value} */
public final static String STRING = "lorem ipsum";
/** STRING_CONCATENATION = {@value} */
public final static String STRING_CONCATENATION = "lorem" + " ipsum";
/** STRING_COMPUTATION = {@value} */
public final static String STRING_COMPUTATION = System.getProperty("path.separator");
/** INT = {@value} */
public final static int INT = 42;
/** INT_COMPUTATION = {@value} */
public final static int INT_COMPUTATION = (20 + 1) * 2;
/** INTEGER = {@value} */
public final static Integer INTEGER = 42;
/** INTEGER_COMPUTATION = {@value} */
public final static Integer INTEGER_COMPUTATION = Integer.valueOf("42");
/** ENUM = {@value} */
public final static MyEnum ENUM = MyEnum.VALUE_B;
public enum MyEnum { VALUE_A, VALUE_B };
}
在Eclipse @value
中按原样在 Oracle Javadoc工具中进行了解析:
In Eclipse @value
is resolved as it is in the Oracle Javadoc tool:
STRING = "lorem ipsum"
STRING_CONCATENATION = "lorem ipsum"
STRING_COMPUTATION = [error/unresolved]
INT = 42
INT_COMPUTATION = 42
INTEGER = [error/unresolved]
INTEGER_COMPUTATION = [error/unresolved]
ENUM = [error/unresolved]
结论:将@value
用于基本类型的常量或仅用于String
的常量.
Conclusion: Use @value
for constants of a primitive type or of String
only.
这篇关于Eclipse中的javadoc @value注释问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!