Java Annotations Annotation Learning---two good blogs

Source: Internet
Author: User

In-depth understanding of Java: Annotations (Annotation) Getting Started with custom annotations----http://www.cnblogs.com/peida/archive/2013/04/24/3036689.html

In-depth understanding of Java: Annotations (Annotation)--Annotation Processor-----http://www.cnblogs.com/peida/archive/2013/04/26/3038503.html

One of the first articles mentions:

There are four meta annotations:

For the JDK's explanation:

Documented: Indicates that a comment of a type will be documented through Javadoc and similar default tools.

Inherited: Indicates that the annotation type is automatically inherited.

Retention: Indicates how long comments for the annotation type are to be retained.

Target: Indicates the kind of program element that the annotation type applies to.

Targetand retention respectively have ElementType Retentionpolicy to set.

 Public enum Retentionpolicy {    SOURCE, CLASS, RUNTIME;}
 Public enum ElementType {    TYPE, FIELD, METHOD, PARAMETER, CONSTRUCTOR, local_variable, Annotation_type, package;}

So you need to look at the meanings of the ElementType and Retentionpolicy enum types:

ElementType:

annotation_type Annotation Type declaration
CONSTRUCTOR constructor Method declaration
Field field declaration (including enumeration constants)
local_variable local variable declaration
Method declaration
Package Declaration
PARAMETER parameter declaration
Type class, interface (including annotation type), or enumeration declaration

Retentionpolicy constants of this enumeration type describe the different strategies for preserving annotations.

The class compiler will record annotations in the class file, but the VM does not need to keep annotations at run time.
The runtime compiler records annotations in the class file, and the VM retains comments at run time, so it can be read in a reflective manner.
The comment that the SOURCE compiler will discard.

But there is a problem:

Look at a document that says a specific annotation @tx ("template") can only be used in the main method, if the inheritance is not effective, you need to see why this is.

Java Annotations Annotation Learning---two good blogs

Related Article

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.