How can you escape the @ character in javadoc?

前端 未结 5 1148
后悔当初
后悔当初 2020-12-02 08:54

How can I escape the @ symbol in javadoc? I am trying to use it inside a {@code} tag, which is inside

 tags.

I alre

相关标签:
5条回答
  • 2020-12-02 09:22

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

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

    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!

    0 讨论(0)
  • 2020-12-02 09:30

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

    0 讨论(0)
  • 2020-12-02 09:40

    An alternative approach from https://stackoverflow.com/a/46332643/208581 ... is to use a similar but different character rather than escape the character: (This answer is copied from the source answer)


    One way to get around this is to use a different character that looks similar to the standard "@" symbol.

    1. @ (U+FF20): FULLWIDTH COMMERCIAL AT
    2. ⓐ (U+24D0): CIRCLED LATIN SMALL LETTER A

    Being similar but different to

    1. @ (U+0040): COMMERCIAL AT (the normal one that is broken)
    0 讨论(0)
  • 2020-12-02 09:43

    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>
     */
    
    0 讨论(0)
提交回复
热议问题