Java annotations Retention, documented, inherited, Target introduction

Source: Internet
Author: User

retention annotation---(Retention's translation reservation)

Retention (reserved) Note that this type of annotation is retained at that stage. There are three values:
1.retentionpolicy.source--This type of annotations is preserved only at the source level and is ignored at compile time
2.retentionpolicy.class--This type of annotations is preserved at compile time and exists in the CLASS file, but the JVM ignores
3.retentionpolicy.runtime--This type of annotations will be retained by the JVM, so they can be read and used by the JVM or other code that uses the reflection mechanism at runtime.


Documented annotations

Documented annotations indicate that this annotation should be recorded by the Javadoc tool. By default, Javadoc is not included in annotations. However, if a @Documented is specified when the annotation is declared, it is processed by a tool such as Javadoc, so the annotation type information is also included in the generated document.


Inherited annotated---(translation Genetics of inherited)
@Inherited: Allows subclasses to inherit annotations from the parent class.


@Target annotations

The target annotation illustrates the range of objects that annotation modifies: annotation can be used for packages, types (classes, interfaces, enumerations, annotation types), type members (methods, constructor methods, member variables, enumeration values), Method parameters and local variables (such as loop variables, catch parameters). Target can be more clearly decorated by using target in the declaration of the annotation type.

@Target (Elementtype.type)//interfaces, classes, enumerations, annotations
@Target (Elementtype.field)//fields, constants for enumerations
@Target (Elementtype.method)//method
@Target (Elementtype.parameter)//Method parameters
@Target (Elementtype.constructor)//constructor
@Target (elementtype.local_variable)//local variable
@Target (Elementtype.annotation_type)//annotations
@Target (Elementtype.package)///Package

Java annotations Retention, documented, inherited, Target introduction

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.