This article is participating in “Java Theme Month – Java Debug Notes Event”, see < Event link > for more details.
Question: How do I use Javadoc syntax to refer to methods in other classes?
Currently, I’m using this Javadoc syntax to refer to methods in other classes:
@see {@link com.my.package.Class#method()}
Copy the code
From what I’ve read in the documentation, this is the correct way to do this. But when I generate this Javadoc, I first get the 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()}
Copy the code
The generated HTML code is:
"," <code>com.my.package.Class#method()}</code> ","
Copy the code
Can anyone tell me what’s going on and any hints on how to fix the problem?
According to the ASCII table, the characters 123 and 64 for wold represent {and @ respectively, so, according to the documentation, why are these characters invalid when this syntax is correct?
Answer 1:
For Javadoc’s @see, you don’t need @link; Javadoc will create a link for you. try
@see com.my.package.Class#method()
Copy the code
Answer 2:
In addition to @see, a more general way to refer to another class and its methods is {@link somepackage.someclass# someMethod (paramTypes)}. This has the advantage of being used in the middle of javadoc descriptions.
According to the Javadoc documentation, the @Link tag describes:
This tag is very similar to @see — both require the same reference and accept exactly the same syntax for package. class# member and label. The main difference is that {@link} generates an embedded link instead of putting the link in the “See also” section. Similarly, the {@link} tag begins and ends with curly braces to separate it from the rest of the inline text.