如何使用 Javadoc @link 到枚举值

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/1521239/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-12 13:46:26  来源:igfitidea点击:

How to @link to a Enum Value using Javadoc

javajavadoc

提问by Christer Fahlgren

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

使用 Javadoc 1.5,我无法创建指向枚举值的 @link。

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:

然后使用如下链接参考 Javadoc for Earth:

{@link Planet.EARTH}

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

我也尝试过这种{@link Planet#EARTH}风格,但无济于事。

Anyone know if this is doable at all?

有谁知道这是否可行?

采纳答案by aperkins

The #style works for me:

这种#风格对我有用:

{@link Planet#EARTH}

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

关键是Planet包必须是进口的,或者Planet必须是完全合格的——即:

{@link com.yourpackage.Planet#EARTH}

回答by sfussenegger

I'm using Eclipse to check this, but

我正在使用 Eclipse 来检查这一点,但是

{@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.

反正。不确定 Eclipse 使用什么来生成 Javadoc,但我使用的是 JDK6。不过,也许@see 可以为您解决问题。

回答by Hyman

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

只要它是导入的,您就可以链接它(但是当您这样做时,IMO 会使导入变得混乱-代码中使用了哪些内容,javadoc 中使用了哪些内容?我喜欢只使用完全限定名称)。

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

但是是的,Eclipse 可以处理这一切并且是标准的

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

如果您使用 Eclipse,Ctrl + Shift + O(在 PC 上)或 Cmd + Shift + O(在 Mac 上)会自动调整您的导入(这意味着如果您没有使用额外的导入,它们将被删除,以及添加您需要的任何进口)。