How can I use “<” and “>” in javadoc without formatting?

前端 未结 8 1863
面向向阳花
面向向阳花 2020-12-02 13:56

If I write in a javadoc, it does not appear, because tags have special functions on formatting texts.

How can I show this chars in a

相关标签:
8条回答
  • 2020-12-02 14:24

    Recent versions of JavaDoc support {@literal A<B>C}; this outputs the content correctly (escaping the '<' and '>' in the generated HTML).

    See http://download.oracle.com/javase/1.5.0/docs/guide/javadoc/whatsnew-1.5.0.html

    0 讨论(0)
  • 2020-12-02 14:27

    If you set maven up to use markdown, you can just surround it with backticks.

    `A<B>C` reads a bit nicer than {@code A<B>C}

    0 讨论(0)
  • 2020-12-02 14:33

    Escape them as HTML: &lt; and &gt;

    0 讨论(0)
  • 2020-12-02 14:36

    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
       A<B>C
    
       D<E>F
    }</pre>
    
    0 讨论(0)
  • 2020-12-02 14:40

    You only need to use the HTML equivalent for one of the angle brackets. The < can be represented as either &lt; or &#60;. Here's a sample taken from real 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>
    
    0 讨论(0)
  • 2020-12-02 14:47

    You can use &lt; for < and &gt; for > .

    0 讨论(0)
提交回复
热议问题