Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to @link to a Enum Value using Javadoc

Tags:

java

javadoc

People also ask

Can enum be subclassed?

We've learned that we can't create a subclass of an existing enum. However, an interface is extensible. Therefore, we can emulate extensible enums by implementing an interface.

What does enum valueOf return?

valueOf. Returns the enum constant of the specified enum type with the specified name. The name must match exactly an identifier used to declare an enum constant in this type. (Extraneous whitespace characters are not permitted.)

Can you have methods in enums?

The enum class body can include methods and other fields. The compiler automatically adds some special methods when it creates an enum. For example, they have a static values method that returns an array containing all of the values of the enum in the order they are declared.


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}

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.


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