我希望来自 A_CONSTANT
的字符串成为 ClassB
注释的一部分:
package my.stuff;
public class ClassA {
/** Shows the string just fine: {@value} */
public static final String A_CONSTANT = "show this in comments";
}
package my.stuff;
/**
* Does not give me the string: {@value my.stuff.ClassA#A_CONSTANT}
* Neither does this: {@value ClassA#A_CONSTANT}
*
* @see my.stuff.ClassA#A_CONSTANT
*/
public class ClassB {
}
ClassA
中的 {@value}
将鼠标悬停在常量名称上时显示字符串内容;没关系。
此外,@see
标记通过链接到 A_CONSTANT
在 ClassB
中发挥作用。
但是 ClassB
中的两次 {@value ...}
尝试都失败了:我看到了文字 {@value ...}
部分而不是 A_CONSTANT
悬停在 ClassB
上时的内容。
documentation告诉我使用以下我认为我做过的符号:{@value package.class#field}
。
this question 的答案还建议使用上述符号。
This与我的问题基本相同,但没有得到回答。
如何在其他类的注释中显示常量的字符串内容?
我在 Windows 7 x86 上使用 Eclipse Juno。
提前致谢。
编辑:
在我的项目上运行 javadoc.exe 时 {@value my.stuff.ClassA#A_CONSTANT}
解析为正确的字符串。
这就是为什么我稍微改变了问题:
为什么 Eclipse 在鼠标悬停时不显示常量的字符串,而 javadoc.exe 没有问题?
最佳答案
这似乎是 Eclipse 中的错误。稍微修改 the docs 中的示例:
public class TestClass {
/**
* The value of this constant is {@value}.
*/
// In Eclipse this shows: The value of this constant is "<script>".
public static final String SCRIPT_START = "<script>";
/**
* Evaluates the script starting with {@value TestClass#SCRIPT_START}.
*/
// In Eclipse this shows: Evaluates the script starting with {@value TestClass#SCRIPT_START}.
public void test1() {
/**
* Evaluates the script starting with {@value #SCRIPT_START}.
*/
// In Eclipse this shows: Evaluates the script starting with "<script>".
public void test2() {
}
}
A bug已为此使用 Eclipse 创建。
关于java - 为什么 Eclipse 在另一个类中使用时不能处理 @value?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18832552/