@Documented annotation in java

What's the purpose of @Documented annotation in java?

I saw the documentation, but could not get much from it. Can someone point out with the help of an clear example

-------------Problems Reply------------

@Documented is a meta-annotation. You apply @Documented when defining an annotation, to ensure that classes using your annotation show this in their generated JavaDoc. I've not seen much use of it, but there is an example here. An earlier question suggests that it doesn't work automatically in Eclipse, but I've tested in Eclipse 3.6, and my annotations appear in the JavaDoc popups whether or not I attach the @Documented annotation to them.

Here's an example from Spring, which ensures that transactional methods are marked as such in the JavaDoc:

@Target({ElementType.METHOD, ElementType.TYPE})
public @interface Transactional {

If an annotation @InWork is @documented, for every class having @InWork, the text generated by javadoc will contain @InWork text, as a reference to the annotation.


@Inherited // for descenders of the annotation to have the @documented feature automatically
@Retention(RetentionPolicy.RUNTIME) // must be there
public @interface InWork {
String value();

annotated target:

* annotated class
@InWork(value = "")
public class MainApp {

The JavaDoc text:

@Documented annotation in java

So, you have to decide, if the annotation should be shown in the Javadoc text, and if yes, set @documented to it.

The information above is taken from Oracle documentation.

Please, notice, that in Eclipse you'll see in Javadoc generated text ALL annotations, are they @documented, or not. It is still correct for 4.3 version.

I found a useful page in the Java Tutorials which gives examples and more explanation for a number of standard annotations, including one use of @Documented. Specifically, look at the Note block at the bottom for the Preamble example (section Documentation).

Category:java Views:0 Time:2011-04-08

Related post

  • Is there a way to use annotations in Java to replace accessors? 2008-12-08

    I'm a little new to the Java 5 annotations and I'm curious if either of these are possible: This annotation would generate a simple getter and setter for you. @attribute private String var = ""; The @NotNull annotation indicates that a variable conno

  • Now that we have annotations in java, is xdoclet legacy? 2009-03-04

    I came accross the xdoclet project and see it enjoys/ed high popularity. So the question is, now that we have annotations in java: is xdoclet legacy? Or is there something to xdoclet I didn't see/understand. --------------Solutions------------- XDocl

  • Should example xml in an xsd documentation annotation be escaped? 2009-07-06

    Lets say I have an xsd schema and I have several <annotation/> elements with <documentation/> elements in them. If I wanted to place example xml in the <documentation/> elements, should I escape the example xml? e.g.: <annotation

  • How To Replace @Resource Annotation with Java 1.4 Compliant Version 2010-06-14

    I have a test class that has a @Resource annotation for a setter and I need to make it Java 1.4 compliant, so obviously the annotation has to go. I'm using Spring. So, how would I replace something like @Resource("my.resource") so that the setter get

  • Combine annotations in Java 2010-08-08

    How can I combine annotations in Java? EDIT I was asking if I two annotations a and b, can I combine to a single annotations c? If possible, how do I do that? --------------Solutions------------- Assuming you want to have multiple annotations on a si

  • Is there an unsupported operation annotation in Java? 2010-10-27

    Are there any annotations in java which mark a method as unsupported? E.g. Let's say I'm writing a new class which implements the java.util.List interface. The add() methods in this interface are optional and I don't need them in my implementation an

  • help me understanding annotation in java 2011-04-16

    I was trying to go through some online material to learn annotation in java In the following code can any one please let me know what happened to my dear "Hello world" string which i passed in this line: @Test_Target(doTestTarget="Hello World !") @Ta

  • Annotation in Java Interface 2011-11-30

    Is there a way say, import org.junit.Test; public interface ITest { @Test public void runTest(); } when I inherit this in a class it will automatically do this public class Test implements ITest { @Test public void runTest() { } } instead of @Overrid

  • JAXB Documentation Annotation 2009-01-22

    I have the following java class with the JAXB @XMLRootElement annotation @XmlRootElement(name="ClientData") public class ClientData { /** * The first address field of the person */ private String address1 = null; } which produces this xml fragment wh

  • Best-practice for documenting available/required Java properties file contents 2009-04-08

    Is there a well-established approach for documenting Java "properties" file contents, including: specifying the data type/contents expected for a given key specifying whether a key is required for the application to function providing a description o

  • Should I use JavaDoc deprecation or the annotation in Java? 2011-02-18

    There are at the moment, two ways to mark code as depreacted in java. Via JavaDoc /* * @deprecated */ Or as an annotation: @Deprecated This is my problem - I find it a bit too much to declare both, when marking a method as deprecated when using Eclip

  • @GuardedBy annotation with java.util.concurrent.locks.ReadWriteLock 2011-10-19

    What is a proper/preferred way to annotate fields that are protected with a ReadWriteLock so that tools like FindBugs can leverage the annotation? Should the name of the ReadWriteLock simply be written in the @GuardedBy annotation. Is there ever a re

  • Insert custom annotation in java 'field' using annotate plugin + JAXB (upon xsd -> java) 2012-03-21

    Use case: Wanna insert custom annotation to fields in java class generated by JAXB Problem: Using Annotate plugin + JAXB [1], am able to successfully insert custom annotations but they are getting inserted at getter method rather than field. Morphia

  • Why is not possible to extend annotations in Java? 2009-10-26

    I don't understand why there is no inheritance in Java annotations, just as Java classes. I think it would be very useful. For example: I want to know if a given annotation is a validator. With inheritance, I could reflexively navigate through superc

  • @XmlElementRefs & @XmlElementRef annotations in Java 2010-01-27

    Can some please explain to me what do @XmlElementRefs and @XmlElementRef annotations mean in Java and what is their use.. EDIT: @skaffman okay, suppose I have one such collection @XmlElementRefs({ @XmlElementRef(name="ElementA", type=ClassA), @XmlEle

  • Documentation for ArcObjects' Java system properties 2010-03-15

    I'm currently debugging a Java application which uses the ESRI ArcObjects library. As the ArcObjects themselves are COM-classes and interfaces an integrated COM-bridge is used, which seems to be a stripped-down version of JIntegra. It occurred to me,

  • @UniqueConstraint annotation in Java 2010-06-27

    I have a Java bean. Now, I want to be sure that the field should be unique. I am using following code: @UniqueConstraint(columnNames={"username"}) public String username; But am getting some error: @UniqueConstraint is dissallowed for this location W

  • Is it possible to read the value of a annotation in java? 2010-11-28

    this is my code: @Column(columnName="firstname") private String firstName; @Column(columnName="lastname") private String lastName; public String getFirstName() { return firstName; } public void setFirstName(String firstName) { this.firstName = firstN

  • Is there any spring hibernate annotations based java web cms 2011-03-10

    Is there any java cms for websites which uses spring hibernate annotation , which can make building sites easy. Like user registration from with fields , login with spring security and some basic functioanlity. Actually i am not sure what product i w

Copyright (C) dskims.com, All Rights Reserved.

processed in 0.104 (s). 11 q(s)