Search code examples
javaannotations

What does the @code java annotation do


I tried searching through the Oracle documentation for an explanation of what the @code java annotation does.

From a previous question, I realized that it has something to do with html, but I'm not sure exactly what...

Would it be correct to say that by default javadoc is parsed as HTML... But placing the @code annotation next to some javadoc text will indicate that it should be treated as code, and not parsed/rendered in the usual way? So for example:

    /**
    *This is how to declare an int variable {@code int var=1;}
    */

Would that be a proper example of its use?


Solution

  • {@code ...} is a Javadoc tag that tells Javadoc that the text inside the braces is source code and should not be treated as HTML. Javadoc should also format the text in a code block differently than the other text. This is a similar concept to the "code sample" text that the editor for StackOverflow uses when you format a question or answer.

    Javadocs are specially-formatted source code comments for class descriptions, constructors, and methods to help generate HTML documentation about source code. For example the Java API is fully documented using Javadocs for reading online or in an IDE. See the Java API Documentation Generator for details.