ChatGPT解决这个技术问题 Extra ChatGPT

Linking to an external URL in Javadoc?

Something like:

/**
 * See {@linktourl http://google.com}
 */

A
Arsen Khachaturyan

This creates a "See Also" heading containing the link, i.e.:

/**
 * @see <a href="http://google.com">http://google.com</a>
 */

will render as:

See Also: http://google.com

whereas this:

/**
 * See <a href="http://google.com">http://google.com</a>
 */

will create an in-line link:

See http://google.com


If anyone is interested, since I just had to look it up: According to the Javadoc spec the @see tag comes after the @param/@return tags and before the @since/@serial/@deprecated tags.
Just in case, Intellij 13 does not seem to support this tag. It does support in-line links. Is the tag somehow deprecated?
I recommend <a href="http://google.com" target="_top">http://google.com</a>. The reason for adding target="_top" is because some of the generated javadoc html files make use of frames, and you probably want the navigation to affect the whole page rather than just the current frame.
why is it so complicated to add a URL link to a javadoc ? who thought that HTML was a good idea... /facepalm
If someone else is as lame as me and searching for the difference between the in-line version and the other for hours: Mind the '@' before 'See' ;)
m
matthias krull

Taken from the javadoc spec

@see <a href="URL#value">label</a> : Adds a link as defined by URL#value. The URL#value is a relative or absolute URL. The Javadoc tool distinguishes this from other cases by looking for a less-than symbol (<) as the first character.

For example : @see <a href="http://www.google.com">Google</a>


Weird; I swear I only added in the backticks; I don't know where the example went to...
I think we had some kind of concurrent edit problem. I was putting them in also.
Fair enough. You're missing the backticks in the first line of your blockquote, though....
@see is not needed. The javadocs can be formatted with html tags, so it's only necessary the "a" tag.
@GabrielLlamas True, but the original question implies this is how it's being used. It's useful to know that it specifically does work in a see-also field, which is where a lot of people will want it.
O
Orlando DFree

Javadocs don't offer any special tools for external links, so you should just use standard html:

See <a href="http://groversmill.com/">Grover's Mill</a> for a history of the
Martian invasion.

or

@see <a href="http://groversmill.com/">Grover's Mill</a> for a history of 
the Martian invasion.

Don't use {@link ...} or {@linkplain ...} because these are for links to the javadocs of other classes and methods.


S
Sergej

Hard to find a clear answer from the Oracle site. The following is from javax.ws.rs.core.HttpHeaders.java:

/**
 * See {@link <a href="http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html#sec14.1">HTTP/1.1 documentation</a>}.
 */
public static final String ACCEPT = "Accept";

/**
 * See {@link <a href="http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html#sec14.2">HTTP/1.1 documentation</a>}.
 */
public static final String ACCEPT_CHARSET = "Accept-Charset";

What is the significance of wrapping the <a> html tag with the {@link ...}?
This is probably a mistake because the javadoc documentation does not mention this form, in it does not make a difference from a raw <a>.
The {@link xxx} here isn't right. {@link xxx} is for linking to other classes and methods in your source code. It's unnecessary here. The rest of it is fine.
This construct is not allowed by Java 8 standards (doclint on).
This is plain wrong. The correct usage as per reference and documentation is {@link package.class#member label}