127

Using JavaDoc, how can I reference the value of a final static field in the class?

I want the ??? in this example replaced by the value of the 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";

}
Mogsdad
  • 44,709
  • 21
  • 151
  • 275
Simon
  • 4,103
  • 7
  • 28
  • 53

1 Answers1

246

Do you mean {@value #STATIC_FIELD}?

user207421
  • 305,947
  • 44
  • 307
  • 483
  • Thanks for your answer! I edited my question in order to make it clear. It would be perfect if the value of the field would be shown in the JavaDoc directly... – Simon Oct 23 '11 at 20:41
  • 3
    can this be referenced in other classes as well? when I tried to do that it didn't work out for me. – Rajith Gun Hewage Nov 29 '16 at 09:10
  • it is always the # :) – João Rebelo Mar 07 '17 at 11:30
  • 48
    @RajithGunHewage, you can reference it from another class like `{@value com.package.other.Clazz#STATIC_FIELD}` – Sean Sep 25 '17 at 19:47
  • 4
    Just in case, for non-primitive constants it will be {@link #STATIC_NON_PRIMITIVE_FIELD} – Yuriy Jul 18 '18 at 10:45
  • 1
    @Sean, as a matter of fact, it should be by using {@link com.package.other.Clazz#STATIC_FIELD} – Cristian Ebbens Apr 05 '19 at 08:18
  • 6
    @Yuriy That's not correct. `{@link ...}` provides a link to the Javadoc of the named field, which in turn does not provide the value. `{@value ...}` provides the actual value, which is what was asked for. 'Non-primitive' has exactly nothing to do with it. See the example of `{@value ...}` in the Javadoc tool documentation, for instance, which uses `java.lang.String`. – user207421 Aug 27 '19 at 04:56
  • thanks for pointing out my mistake...appreciated, sincerely – aran Feb 22 '21 at 03:15