【问题标题】:How can I hyperlink one comment from another comment location in javadoc如何在 javadoc 中的另一个评论位置超链接一个评论
【发布时间】:2014-10-26 11:26:01
【问题描述】:

我想为可以从代码的任何部分引用的注释块编写超链接/链接。

例如,我在课堂上提到了一些 cmets:

  /**
   * Really long comments with some case based detail
   */
    //Code goes here...
    //Code goes here...

// Hey I want you to please have a look at **This Comments** please before making any changes ...
public void myMethod(){....

// Hey I want you to please have a look at **This Comments** please before making any changes ...
public void yetAnotherMethod(){....

For above the **This Comments** should be a link to details mentioned at the top.

【问题讨论】:

    标签: java formatting documentation comments javadoc


    【解决方案1】:

    引用/链接

    您可以使用@link@see javadoc 标签来插入指向其他类型或字段的链接。

    您还可以像这样指定链接的文本:

    {@link ClassName#fieldName Text to display}
    
    @see ClassName#fieldName Text to display
    

    例子:

    我使用了一个字段来定义注释,但你可以链接到类、方法、字段等:

    /**
     * Important to know that...
     */
    private static final byte IMPORTANT_NOTE = 0;
    
    /**
     * Before making changes, see {@link #IMPORTANT_NOTE Important note}.
     */
    public void myMethod() {}
    
    /**
     * @see #IMPORTANT_NOTE Important to check this!
     */
    public void myMethod2() {}
    

    内联

    您还可以使用@value 将静态字段的值内联到 javadoc 中,例如:

    private static final String IMPORTANT_NOTE = "Important to know that...";
    
    /**
     * See this important note: {@value #IMPORTANT_NOTE}
     */
    public void myMethod() {}
    

    【讨论】:

    • 感谢@icza,但实际上这听起来像是一个 hack,因为它总是需要为此保留一个静态虚拟变量。仍在寻找更多方法来做到这一点。
    • 这在我的情况下不起作用。我的意思是它没有转向链接
    猜你喜欢
    • 1970-01-01
    • 2020-01-09
    • 1970-01-01
    • 2015-01-24
    • 2023-03-16
    • 1970-01-01
    • 1970-01-01
    • 2014-07-27
    • 1970-01-01
    相关资源
    最近更新 更多