Sankalp
Sankalp

Reputation: 2086

How can I hyperlink one comment from another comment location in javadoc

I want to write a hyperlink/link for a block of comment which I can refer from any part of code.

For example I have mentioned some comments on top of class:

  /**
   * 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.

Upvotes: 4

Views: 4398

Answers (1)

icza
icza

Reputation: 418077

Referencing / Linking

You can use @link and @see javadoc tags to insert links to another types or fields.

You can also specify the text of the links like this:

{@link ClassName#fieldName Text to display}

@see ClassName#fieldName Text to display

Examples:

I used a field to define the comment, but you can link to Class, method, field etc.:

/**
 * 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() {}

Inlining

You can also inline the values of static fields into the javadoc using @value, example:

private static final String IMPORTANT_NOTE = "Important to know that...";

/**
 * See this important note: {@value #IMPORTANT_NOTE}
 */
public void myMethod() {}

Upvotes: 2

Related Questions