273
votes

Currently I'm referencing methods in other classes with this Javadoc syntax:

@see {@link com.my.package.Class#method()}

And in what I understand from the documentation this is the correct way to do this. But now to the funny part, or frustrating. When I generate this javadoc I first of all get following error:

warning - Tag @see:illegal character: "123" in "{@link com.my.package.Class#method()}"
warning - Tag @see:illegal character: "64" in "{@link com.my.package.Class#method()}"
warning - Tag @see: reference not found: {@link com.my.package.Class#method()}

The Generated HTML code of this is:

"," <code>com.my.package.Class#method()}</code> ","

And of course I have no link. Can anyone tell me what's happening, and any hints on how to fix this?

According to the ASCII table characters 123 and 64 for wold represent { and @, so why aren't these characters valid when this syntax is correct according to the documentation?

3
Just to check... have you read the Javadoc Generator documentation? docs.oracle.com/javase/7/docs/technotes/tools/windows/… - Diogo Moreira
Did you import com.my.package.Class in the class this JavaDoc is written? The reference not found seems odd. On the other hand, I've never used them combined but there's a chance that @see and @link conflict with each other, taking that @see generates its own seciton it wouldn't surprise me. - Fritz
@DiogoMoreira - No I havn't read about the engine, but I will check it out. - Robert
@Gamb - Of course it's not my actual Javadoc input;-) Yes all imports are in place. - Robert
A similar error occurs if you put a raw hyperlink as the value for the @see tag in your javadoc. To fix it in this case wrap the hyperlink in an html anchor element: /** @see <a href="http://example.com">Example</a> */ - cyber-monk

3 Answers

326
votes

For the Javadoc tag @see, you don't need to use @link; Javadoc will create a link for you. Try

@see com.my.package.Class#method()

Here's more info about @see.

174
votes

Aside from @see, a more general way of refering to another class and possibly method of that class is {@link somepackage.SomeClass#someMethod(paramTypes)}. This has the benefit of being usable in the middle of a javadoc description.

From the javadoc documentation (description of the @link tag):

This tag is very simliar to @see – both require the same references and accept exactly the same syntax for package.class#member and label. The main difference is that {@link} generates an in-line link rather than placing the link in the "See Also" section. Also, the {@link} tag begins and ends with curly braces to separate it from the rest of the in-line text.

86
votes

So the solution to the original problem is that you don't need both the "@see" and the "{@link...}" references on the same line. The "@link" tag is self-sufficient and, as noted, you can put it anywhere in the javadoc block. So you can mix the two approaches:

/**
 * some javadoc stuff
 * {@link com.my.package.Class#method()}
 * more stuff
 * @see com.my.package.AnotherClass
 */