如何在不格式化的情况下在 javadoc 中使用“<”和“>”?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/2898897/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How can I use "<" and ">" in javadoc without formatting?
提问by Tom Brito
If I write <xmlElement>
in a javadoc, it does not appear, because tags have special functions on formatting texts.
如果我写<xmlElement>
在 javadoc 中,它不会出现,因为标签具有格式化文本的特殊功能。
How can I show this chars in a javadoc?
如何在 javadoc 中显示此字符?
采纳答案by Pavitar Singh
You can use <
for <and >
for >.
您可以使用<
for <和>
for >。
回答by duffymo
Escape them as HTML: <
and >
将它们转义为 HTML:<
和>
回答by Pops
You only need to use the HTML equivalent for one of the angle brackets. The <
can be represented as either <
or <
. Here's a sample taken from real Javadoc:
您只需要对其中一个尖括号使用 HTML 等效项。的<
可以表示为任一<
或<
。这是取自真实 Javadoc 的示例:
<pre> <complexType> <complexContent> <restriction base="{http://www.w3.org/2001/XMLSchema}anyType"> <sequence> [...]
This displays as:
这显示为:
<complexType>
<complexContent>
<restriction base="{http://www.w3.org/2001/XMLSchema}anyType">
<sequence>
回答by Howard M. Lewis Ship
Recent versions of JavaDoc support {@literal A<B>C}; this outputs the content correctly (escaping the '<' and '>' in the generated HTML).
最新版本的 JavaDoc 支持 {@literal A<B>C};这将正确输出内容(转义生成的 HTML 中的“<”和“>”)。
See http://download.oracle.com/javase/1.5.0/docs/guide/javadoc/whatsnew-1.5.0.html
请参阅http://download.oracle.com/javase/1.5.0/docs/guide/javadoc/whatsnew-1.5.0.html
回答by Etienne Delavennat
Considering XML is actual code, I believe XML snippets in Javadoc are better suited for the {@code A<B>C} tag rather than the {@literal A<B>C} tag.
考虑到 XML 是实际代码,我相信 Javadoc 中的 XML 片段更适合 {@code A<B>C} 标签而不是 {@literal A<B>C} 标签。
The {@code } tag uses a fixed-width font which makes its content standout as actual code.
{@code} 标签使用固定宽度的字体,这使得它的内容与实际代码一样突出。
回答by Owen
If you set maven up to use markdown, you can just surround it with backticks.
如果您将 maven 设置为使用 markdown,则可以用反引号将其括起来。
`A<B>C`
reads a bit nicer than {@code A<B>C}
`A<B>C`
读起来比 {@code A<B>C}
回答by Serg
Interposition of <pre> and {@code} saves angle brackets and empty lines in javadocs and is widely used, see java.util.Stream for example.
<pre> 和 {@code} 的插入在javadocs 中保存尖括号和空行并且被广泛使用,例如参见java.util.Stream。
<pre>{@code
A<B>C
D<E>F
}</pre>
回答by ivanjermakov
Just surround it with {@code}
like this:
就像这样包围它{@code}
:
{@code <xmlElement>}