简体   繁体   English

如何在不格式化的情况下在 javadoc 中使用“<”和“>”?

[英]How can I use "<" and ">" in javadoc without formatting?

If I write <xmlElement> in a javadoc, it does not appear, because tags have special functions on formatting texts.如果我在 javadoc 中编写<xmlElement> ,它不会出现,因为标签对格式化文本具有特殊功能。

How can I show this chars in a javadoc?如何在 javadoc 中显示此字符?

You can use &lt; 您可以使用&lt; for < and &gt; 对于<&gt; for > . >

Recent versions of JavaDoc support {@literal A<B>C}; JavaDoc的最新版本支持{@literal A <B> C}; this outputs the content correctly (escaping the '<' and '>' in the generated HTML). 这样可以正确输出内容(在生成的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

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代码段比{@literal A <B> C}标签更适合{@code A <B> C}标签。

The {@code } tag uses a fixed-width font which makes its content standout as actual code. {@code}标记使用固定宽度的字体,该字体的内容作为实际代码脱颖而出。

Escape them as HTML: &lt; 将它们转为HTML: &lt; and &gt; &gt;

You only need to use the HTML equivalent for one of the angle brackets. 您只需要对其中一个尖括号使用等效的HTML。 The < can be represented as either &lt; <可以表示为&lt; or &#60; &#60; . Here's a sample taken from real Javadoc: 这是从真实的Javadoc中获取的示例:

<pre>
&lt;complexType>
  &lt;complexContent>
    &lt;restriction base="{http://www.w3.org/2001/XMLSchema}anyType">
      &lt;sequence>
      [...]

This displays as: 显示为:

<complexType>
   <complexContent>
     <restriction base="{http://www.w3.org/2001/XMLSchema}anyType">
       <sequence>

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}更好

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>

像这样用{@code}包围它:

{@code <xmlElement>}

In my case where I wanted to put in my javadocs List<SomeClass> ...在我想放入我的 javadocs List<SomeClass> ...

I added an even more specific information by giving the link to my SomeClass , so here is my solution :我通过提供指向我的SomeClass的链接添加了更具体的信息,所以这是我的解决方案:

List<{@link SomeClass}>

Which resulted to a clean :这导致了一个干净的:

List<SomeClass>

With underlined 'SomeClass' directing to the specified class.带有下划线的“SomeClass”指向指定的类。

(of course if the SomeClass is not in same package, the complete path should be referenced) (当然如果SomeClass不在同一个包中,则应引用完整路径)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM