Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 873
JMS Avatar asked Oct 10 '13 17:10

JMS


People also ask

What does @code mean in JavaDoc?

{@code} is a Javadoc tag that came with Java 5. A code snippet embedded within {@code} will display our special characters correctly so they don't need to be manually escaped. However, indentation and line breaks will be lost. This can be rectified by using {@code} together with <pre> , though (see next section).

What does a Java Annotation do?

Java annotations are metadata (data about data) for our program source code. They provide additional information about the program to the compiler but are not part of the program itself. These annotations do not affect the execution of the compiled program. Let's take an example of @Override annotation.

What is the use of @interface annotation?

Notice the @interface keyword. This signals to the Java compiler that this is a Java annotation definition. Notice that each element is defined similarly to a method definition in an interface. It has a data type and a name.

What is @interface annotation in Java?

Annotation is defined like a ordinary Java interface, but with an '@' preceding the interface keyword (i.e., @interface ). You can declare methods inside an annotation definition (just like declaring abstract method inside an interface). These methods are called elements instead.


1 Answers

{@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.

like image 151
dkatzel Avatar answered Sep 28 '22 02:09

dkatzel