Search code examples
javaescapingjavadoc

How can you escape the @ character in javadoc?


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

I already tried the html escape &#64; sequence, but that didn't work.


Solution

  • 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!