如何在类中引用最终静态字段的值?


96

使用JavaDoc,如何在类中引用最终静态字段的值?

我希望???在此示例中将其替换为field的值STATIC_FIELD

/**
 * This is a simple class with only one static field with the value ???.
 */
public class Simple {

    /**
     * We can reference the value with {@value} here, 
     * but how do we reference it in the class JavaDoc?
     */
    public static final String STATIC_FIELD = "simple static field";

}

Answers:


194

你的意思是{@value #STATIC_FIELD}


3
可以在其他类中引用吗?当我尝试这样做时,它对我没有效果。
拉杰斯·冈·希瓦奇

20
@RajithGunHewage,你可以从另一个类喜欢引用它{@value com.package.other.Clazz#STATIC_FIELD}
肖恩

2
以防万一,对于非基本常量,它将为{@link #STATIC_NON_PRIMITIVE_FIELD}
Yuriy

1
@Sean实际上应该使用{@link com.package.other.Clazz#STATIC_FIELD}
Cristian Ebbens

1
@Yuriy这是不正确的。{@link ...}提供指向命名字段的Javadoc的链接,而该链接又不提供值。{@value ...}提供所需的实际值。“非原始”与它完全无关。例如,请参阅{@value ...}Javadoc工具文档中的示例,该示例使用java.lang.String
罗恩侯爵,
By using our site, you acknowledge that you have read and understand our Cookie Policy and Privacy Policy.
Licensed under cc by-sa 3.0 with attribution required.