Creating a link to method/class in Java Docs

Posted on 22-01-2013 11:54 by graham
Sometimes you might want to add a reference to some other Java class or method in your JavaDoc comment. You do this using the {@link} tag.

Creating a link to method in the same class

For example, let's say we have a deprecated method methodOne and in the comment to it we want to indicate that users ought to use a newer method methodTwo:
* This method is depraced. Use {@link #methodTwo(String, String)} instead.
public void methodOne (String arg1, String arg2)

public void methodTwo (String arg1, String arg2)

Note that hash sign before the method name.

Creating a link to method in another class

To add a link to a method in another class, use:
{@link com.domain.some.package.YourClass#methodTwo(String, String)}

If you want to add an alias to the URL, you can do it by simply inserting it next to the method name in the {@link} tag:
{@link #methodTwo(String, String) your alias}

Creating a link to a class in another package

To link to a class in another package, use the same syntax, but without the # (hash) sign:
{@link com.domain.some.package.YourClass}


Add comment

Has this tutorial been helpful to you? Or do you see anything wrong? We appreciate your opinion!
Your comment:
Show formatting hints
HTML is disallowed, but in your text you can use the following markup
  • [code][/code] for a block of code
  • [tt][/tt] for inline code
  • [link]link href|link anchor[/link] for links
  • [b][/b] for bold text
+ Ask a question
If you have a technical question related to programming and computers, ask it here. Other users will help you solve it!
Unanswered questions
Share your knowledge by helping others solve their problems