@Documented annotation in java

前端 未结 3 1244
陌清茗
陌清茗 2021-01-31 13:08

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 cl

3条回答
  •  再見小時候
    2021-01-31 13:49

    If some our annotation (for example, @InWork) is @Documented, then for every class having that @InWork annotation the text generated by javadoc will contain @InWork text, as a reference to the annotation.

    Annotation:

    @Documented
    @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:

    enter image description here

    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.

提交回复
热议问题