145

Using Javadoc 1.5, I have been unable to create a @link to an Enumeration value.

What I would like to do is to create an Enum like this:

public enum Planet { 

/**
* MERCURY is a fun place.
*/
MERCURY, 

/**
* VENUS is more fun.
*/
VENUS, 

/**
* But nothing beats the Earth.
*/
EARTH,

/**
* Others we know nothing about.
*/ 
OTHERS
}

And then refer to the Javadoc for Earth using a link like this:

{@link Planet.EARTH}

I have tried the {@link Planet#EARTH} style too, but to no avail.

Anyone know if this is doable at all?

Christer Fahlgren
  • 2,414
  • 2
  • 21
  • 16

3 Answers3

237

The # style works for me:

{@link Planet#EARTH}

The key is that the Planet package must be imported, or Planet must be fully qualified - i.e.:

{@link com.yourpackage.Planet#EARTH}
Andrew Tobilko
  • 48,120
  • 14
  • 91
  • 142
aperkins
  • 12,914
  • 4
  • 29
  • 34
  • As sfussenegger noted, Eclipse handles the import for you. – aperkins Oct 05 '09 at 17:21
  • Thanks both answers helpful! I did get it to work using the fully qualified reference. Sometimes the compiler output isn't really helpful in determining what the problem is... – Christer Fahlgren Oct 05 '09 at 17:28
  • 3
    What if enum is defined within class A and one is trying to reference one of its values from class B javadoc? I've found neither A.Planet#EARTH nor A#Planet#EARTH to work for OpenJDK 1.6 update 24 javadoc, although eclipse knows to find declaration with A.Planet#EARTH style. – Stevo Slavić Feb 12 '12 at 17:46
  • Unfortunately that doesn't work if you have a static import of enum. At least in intellij idea there is no way to use a statically imported enum in javadoc, unless you use the fully qualified enum name with packages etc. – dhblah May 29 '15 at 13:47
7

I'm using Eclipse to check this, but

{@link Planet#EARTH}

style seems to work. However, I normally prefer

@see Planet#EARTH

anyway. Not sure what Eclipse uses to generate Javadoc, but I'm using JDK6. Still, maybe @see does the trick for you.

sfussenegger
  • 35,575
  • 15
  • 95
  • 119
  • 4
    I like `@see` but sometimes you need special cases. For example, my orders have an `isWithdrawn()` method, and I specifically say `@return true if the status of this order is equal to OrderStatus#WITHDRAWN, false otherwise` – corsiKa Oct 03 '13 at 17:21
2

As long as it's imported you can link it (but when you do this, IMO it makes the imports messy- what ones are used in code and what ones in javadoc? I like to just use the fully qualified name).

But yes, Eclipse can take care of it all and standard

{@link Planet#EARTH}

works fine.

If your using Eclipse, Ctrl + Shift + O (on PC) or Cmd + Shift + O (on Mac) auto-adjust your imports (this means if you have extra imports not being used, they're removed, as well as adding any imports you need).

Jack
  • 1,250
  • 1
  • 14
  • 26