15

我希望字符串 fromA_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 {

}

将鼠标悬停在常量名称上时, {@value}in向我显示了字符串内容;ClassA没关系。

@see标签还ClassB通过链接到A_CONSTANT.

然而,两次{@value ...}尝试都ClassB失败了:我看到文字{@value ...}部分,而不是A_CONSTANT当鼠标悬停在ClassB.

文档告诉我使用我认为我做过的以下符号:{@value package.class#field}.

这个问题的答案也建议使用上述符号。

与我的问题基本相同,但没有得到回答。

如何在其他类的注释中显示常量的字符串内容?

我在 Windows 7 x86 上使用 Eclipse Juno。

提前致谢。

编辑:

在我的项目上运行 javadoc.exe 时{@value my.stuff.ClassA#A_CONSTANT}解析为正确的字符串。

这就是为什么我稍微改变了这个问题:

为什么 Eclipse 在鼠标悬停时不显示常量的字符串,而 javadoc.exe 没有问题?

Eclipse 中的鼠标悬停:未显示常量的字符串

4

2 回答 2

9

这似乎是 Eclipse 中的一个错误。从文档稍微修改示例:

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() {
  }
}

eclipse为此创建了一个错误。

于 2016-03-23T08:23:49.960 回答
-1

在您链接到此处的 javadoc 参考页面上,在“可以使用标签的位置”下,它引用 @value 可以在字段上使用,但不能在类上使用。在 B 类中,javadoc 在类上,这是无效的。eclipse可能严格遵循该评估,而javadoc.exe对放置更为宽松。

于 2015-01-20T01:37:33.440 回答