Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Code example with annotation in JavaDoc

Tags:

java

javadoc

my JavaDoc doesn't work when I have a code example with an annotation.

Any suggestions?

/**  * <pre>  * public class Demo {  *    @DemoAnnotation  *    public void demoMethod() {  *    }  * }  * </pre>  */  @Retention(RetentionPolicy.RUNTIME) @Target({ElementType.METHOD}) public @interface DemoAnnotation { 
like image 538
John Avatar asked Apr 14 '10 08:04

John


People also ask

How do you write Javadoc code?

Writing Javadoc Comments In general, Javadoc comments are any multi-line comments (" /** ... */ ") that are placed before class, field, or method declarations. They must begin with a slash and two stars, and they can include special tags to describe characteristics like method parameters or return values.

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 is Javadoc give example?

Javadoc is a tool which comes with JDK and it is used for generating Java code documentation in HTML format from Java source code, which requires documentation in a predefined format. Following is a simple example where the lines inside /*…. */ are Java multi-line comments.

Can you use HTML tags in Javadoc comments?

There are no real restrictions on the use of HTML in Javadoc comments. The Javadoc documentation states: Comments are written in HTML - The text must be written in HTML, in that they should use HTML entities and can use HTML tags.


2 Answers

A more general solution: {@literal @}

The {@literal} tag denotes literal text. The enclosed text is interpreted as not containing HTML markup or nested javadoc tags. For example, the doc comment text: {@literal a<B>c} displays in the generated HTML page unchanged: a<B>c -- that is, the <B> is not interpreted as bold.

Requires Java 5+

like image 59
Joe Coder Avatar answered Sep 22 '22 00:09

Joe Coder


You must replace @ with &#064; in your JavaDoc.

like image 25
Espen Avatar answered Sep 22 '22 00:09

Espen