Notes Principle

principle:

Annotation is a kind of interface. Annotation to access information through the relevant java reflection mechanism API. 
Related classes (class frame or tool) according to this information to decide how to use the program elements or change their behavior.

Java language interpreter at work ignores these Annotation, therefore Annotation in the JVM these are "ineffective", and
can only Annotation of these types of information access and processing by supporting tools.
Annotation and interface of the similarities and differences: 

1 , annotition type keyword @interface rather than the interface . It inherits the interface java.lang.annotition.Annotition not declare an interface. 

2 , the Annotation type by definition is unique, limited. Annotation types of methods must be declared with no arguments, no exception to be thrown. These methods define the members Annotation: Method name for members of the name, 
and the method returns a value known as the type of member. The method returns the value must be the type of primitive, Class type, enumerated type, the Annotation type or a front type as one of the array of elements.
Back method can use the default values to declare a default and the default value of the member, null can not serve as members of the default value, which we are very different in non Annotation type defined method. Annotation type and his methods can not be used Annotation types of parameters,
members can not be generic. The return value is the only type of Class methods may be used in a generic Annotation type, because this method can be used to convert various types of converting class Class.
. 3 , and the interface with the Annotation type similar place. They can define constants, static member types (such as enumeration type definition). Annotation type may typically be implemented as an interface or inherit.

* 元注解@Target,@Retention,@Documented,@Inherited 

Original link: https://freewxy.iteye.com/blog/1149128

Notes itself does not do anything, just play a role like xml configuration file the same . Notes are represented by some kind of business sense, annotation processor works behind-source implementation of the above:
First, resolve all the attributes to determine whether there is a specified annotation on the property, if present, according to obtain bean search rules , and then use the reflection principle injection .
If the label on the top field, the field can also obtain reflection Technical Note , according to obtain bean search rules , and then use anti- shot injection techniques .

 

Guess you like

Origin www.cnblogs.com/UncleWang001/p/10948660.html