Javadoc linking to a class in another package

JavaJavadoc

Java Problem Overview


I have two packages, Shapes and Fruits:

com.myproject.Shapes.
    Circle
    Square
    Triangle
com.myproject.Fruits.
    Apple
    Orange

I am writing the JavaDoc for Apple and need to provide an {@link} to Square.

I have tried all of the following, and none of them work:

{@link Square}
{@link com.myproject.Square}

I've been able to find documentation for linking to: (a) classes within the same package, or (b) externals URLs, but not classes in another package.

Any ideas what the correct syntax should be? Thanks!

Java Solutions


Solution 1 - Java

The correct syntax variants are

{@link [<package>.]<class>[#<method>]}
{@link #<method>}

You were missing a complete package. The following example should be correct

{@link com.myproject.Shapes.Square} 
                     ^^^^^^

Solution 2 - Java

For another package use this syntax:

{@link  package.class#member  label}

In your case this should be:

{@link com.myproject.Shapes.Square Square}

If you want to show only the class name then use the label, if complete path is desired then label is not required.

Reference: http://docs.oracle.com/javase/7/docs/technotes/tools/windows/javadoc.html#link

Solution 3 - Java

The question is pretty old, but adding another answer for anyone having similar issue.

Using @see would give you a clickable link to go to a specified class or method, given that the class, if present in another package, is imported.

In case the class / method being referred is in another module, you will have to add a dependency of that module in the current module, for @see to provide you a clickable link.

/**
 *     @see com.myproject.Square#method(int)
 */

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionIAmYourFajaView Question on Stackoverflow
Solution 1 - JavaJohan SjöbergView Answer on Stackoverflow
Solution 2 - JavaPranav ShahView Answer on Stackoverflow
Solution 3 - JavasssView Answer on Stackoverflow