How to @link to a Enum Value using Javadoc

JavaJavadoc

Java Problem Overview


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?

Java Solutions


Solution 1 - Java

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}

Solution 2 - Java

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.

Solution 3 - Java

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).

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionChrister FahlgrenView Question on Stackoverflow
Solution 1 - JavaaperkinsView Answer on Stackoverflow
Solution 2 - JavasfusseneggerView Answer on Stackoverflow
Solution 3 - JavaJackView Answer on Stackoverflow