如何在javadoc中转义@符号?我试图在一个{@code}标签内使用它,这是在<pre>标签内。

我已经尝试了html转义&#64;顺序,但这没用。


你有了大概的想法,尝试使用八进制表示:&#064;


把它写成HTML实体:

&#064;

摘自文档“javadoc - Java API文档生成器”

如果你想以@字符开始一行,并且不希望它被解释,请使用HTML实体@。

这意味着你可以对任何需要转义的字符使用HTML实体,而且确实可以:

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;.


使用{@literal} javadoc标签:

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

它的javadoc代码如下:

This is an "at" symbol: @

当然,这适用于任何字符,并且是显示任何“特殊”字符的“官方支持”方式。

它也是最直接的——你不需要知道字符的十六进制代码,你可以阅读你输入的东西!


我的解决方案是

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

在15.0.2版本的javadoc工具中修正

从15.0.2开始使用javadoc工具时,此问题现在似乎已修复。

也就是说,在使用javadoc multiline {@code…时不再需要转义@字符。}。

有一个JDK错误记录https://bugs.openjdk.java.net/browse/JDK-8130754…它目前没有被标记为固定的,但它不再在javadoc 15.0.2中复制。