如何添加选项以在 Javadoc 注释中显示 @tags

How to add option to display @tags in Javadoc comments

我有两个自己的注释,用于不同的字段和方法以及 @Deprecated 注释。但是,不像 @Deprecated 注释,它可以在 Javadoc 注释本身中显示,并带有描述,我不能用我自己的注释来做到这一点吗?

小例子:

/**
 * Sends "bar".
 *
 * @deprecated Use {@link #sendFooBar()} instead.
 */
@Deprecated
@MyAnnotation // I want to add a description to this annotation in the comment above
public void sendBar(){
    System.out.prntln("bar");
}

所以我的问题是我必须做什么,以便在评论本身中显示注释并提供评论。

我不能直接将它添加到评论中,因为它会被视为 "wrong tag"。

澄清一下:我不想只是在评论中显示@符号。我知道怎么做了。
我想在 Javadoc 注释中包含类似于 @Deprecated 注释可用的文档(描述)。

注释本身附有 @Documented@Retention(RetentionPolicy.RUNTIME)@Target({ElementType.METHOD, ElementType.FIELD}) 注释。

不可能像你想的那样在javadoc中使用自定义注解。如果您将注释 per specification. The javadoc @deprecated tag is written lowercase whereas the @Deprecated annotation of the Java Language 写成大写,这将变得更加明显。

这是因为 javadoc @deprecated 标记评论了基础方法 and/or 构造函数的弃用,而不是表示 Java @Deprecated 注释本身.因此,您无法按照默认方式在 javadoc 中使用注释。

但是,可以将自定义标签引入 javadoc。解释了如何这样做 here。您还可以考虑在 javadoc 注释的其他地方提及您的注释可能具有的含义。要安全地转义注释名称,只需使用 {@code ...} 结构。