Android SUPPORT LIBRARY AnNotations's Java class library technology original understanding

Android SUPPORRT Library Annotations is a Java library developed in Android for annotations in Android applications. Note is a method for adding metadata (self -explanation information). It can be used to perform some additional processing or provide some additional information during compilation. Android Support Library Annotations provides the following annotations: 1. @intdef: Used to define the constant set of an integer type.This can limit the range of the parameter value and perform a static inspection during compilation. @IntDef({MODE_PRIVATE, MODE_WORLD_READABLE, MODE_WORLD_WRITEABLE}) @Retention(RetentionPolicy.SOURCE) public @interface FileMode {} 2. @StringDef: Used to define a constant set of a string type.It can also limit the range of parameter values and perform static checks during compilation. @StringDef({TYPE_TEXT, TYPE_IMAGE, TYPE_AUDIO, TYPE_VIDEO}) @Retention(RetentionPolicy.SOURCE) public @interface MessageType {} 3. @Colorint: Used to specify an integer that represents color.In the place where the annotation is used, only one effective color value can be passed, otherwise an error will be reported when compiling. public void setBackgroundColor(@ColorInt int color) { // do something } 4. @RequireSpermitMission: It takes a certain method or a certain permissions for marking a method or class to access or access. @RequiresPermission(Manifest.permission.READ_CONTACTS) public void readContacts() { // do something } The technical principles of Android SUPPORT LIBRARY AnNotations include the following aspects: 1. Note definition: Use Java annotations to define@intdef,@stringDef, and @Colorint, etc., specifying the retention strategy of the annotation as the source code level. 2. Note processor: When compiling, the annotation processor will scan the annotations in the source code, extract the metadata information in the annotation, and process it accordingly.For example, for the @intdef annotation, the processor will check whether the parameter type and its value is legal. 3. APT (Annotation Processing Tool): The annotation processor is executed by the APT during the compilation.APT reads the source code file, finds all elements containing annotations, and transmits the processor as a parameter to the APT. 4. Static inspection during compilation: By using Android Support Library Annotations, static checks can be performed during compilation to avoid some common errors. In summary, Android Support Library Annotations provides a convenient way to use annotations in Android applications, and with APT can achieve static checks during compilation.Through reasonable use of these annotations, the readability and maintenance of code can be improved, and some common errors can be reduced. Please note that the above is only a brief introduction to Android Support Library Annotations. In actual use, these annotations should be used in combination with specific scenes and needs.