Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can you escape the @ character in javadoc?

People also ask

Which character is used when using a Javadoc comment?

Javadoc comment is a multiline comment /* */ that starts with the * character and placed above the class definition, interface definition, enum definition, method definition or field definition.

How do I format a Javadoc?

Use the standard style for the Javadoc commentJavadoc only requires a '/**' at the start and a '*/' at the end. In addition to this, use a single star on each additional line: /** * Standard comment. */ public ... /** Compressed comment.

What does @SEE mean in Javadoc?

We can use the @see and @link tag multiple times in a class, package, or method. The @see tag declares references that point to an external link, class, or method. The @link tag can also be used multiple times for declaring inline links or in contrast with other block tags.

What is @since in Javadoc?

Specify the product version when the Java name was added to the API specification (if different from the implementation). For example, if a package, class, interface or member was added to the Java 2 Platform, Standard Edition, API Specification at version 1.2, use: /** * @since 1.2 */


Use the {@literal} javadoc tag:

/**
 * This is an "at" symbol: {@literal @}
 */

The javadoc for this will read:

This is an "at" symbol: @

Of course, this will work for any characters, and is the "officially supported" way of displaying any "special" characters.

It is also the most straighforward - you don't need to know the hex code of the character, and you can read what you've typed!


Just write it as an HTML entity:

@

From the document "javadoc - The Java API Documentation Generator"

If you want to start a line with the @ character and not have it be interpreted, use the HTML entity @.

This implies that you can use HTML entities for any character that you would need to escape, and indeed you can:

The text must be written in HTML with HTML entities and HTML tags. You can use whichever version of HTML your browser supports. The standard doclet generates HTML 3.2-compliant code elsewhere (outside of the documentation comments) with the inclusion of cascading style sheets and frames. HTML 4.0 is preferred for generated files because of the frame sets.

For example, entities for the less than symbol (<) and the greater than symbol (>) should be written as &lt; and &gt;. Similarly, the ampersand (&) should be written as &amp;.


my solution is

/**
 * Mapper Test Helper.
 *
 * add the following annotations above the class
 * <pre>{@code
 * // junit5
 * @literal @ExtendWith(SpringExtension.class)
 * // junit4
 * @literal @RunWith(SpringRunner.class)
 * }</pre>
 */

You got the general idea, try using the octal representation: &#064;


Fixed in javadoc tool from 15.0.2

This issue now appears to be fixed when using javadoc tool from 15.0.2.

That is, we no longer need to escape the @ character when using javadoc multiline {@code ... } block.

There is a JDK bug logged https://bugs.openjdk.java.net/browse/JDK-8130754 ... which is currently not marked as fixed but it no longer reproduces with javadoc 15.0.2.