The seventh lesson in Android annotations

1、@Deprecated

Indicates that the use of this constructor, field, local variable, method, package, parameter, class, etc. is discouraged, usually because it is dangerous or there is a better alternative.

2、@SuppressLint

Lint is a static checker that analyzes and checks the correctness, security, performance, usability and accessibility of Android projects. The inspection objects include XML resources, bitmaps, ProGuard configuration files, source files and even compiled bytecodes. .

For this checker, you can use the @SuppressLint annotation to ignore the specified warning.

3、@Override

Indicates that the definition of the current method will override the method in the superclass

4. Annotation of annotations

Meta annotation Description Value
@Target Indicates where the annotation can be used ElementType.ANNOTATION_TYPE can be applied to annotation types.
ElementType.CONSTRUCTOR can be applied to constructors.
ElementType.FIELD can be applied to fields or attributes. ElementType.LOCAL_VARIABLE can be applied to local variables.
ElementType.METHOD can be applied to method-level annotations.
ElementType.PACKAGE can be applied to package declarations.
ElementType.PARAMETER can be applied to method parameters. ElementType.TYPE can be applied to any element of the class.
@Retention Indicates at what level the annotation information needs to be saved 1. SOURCE: valid in the source file (that is, the source file is reserved)
2. CLASS: valid in the class file (that is, the class is reserved)
3. RUNTIME: valid at runtime (that is, reserved at runtime)
@Documented Indicates that this annotation is included in the Javadoc no
@Inherited Indicates that subclasses are allowed to inherit the annotations in the parent class no

Example:

//表示@Override这个注解只能用于方法,且在源码中有效
@Target(ElementType.METHOD)
@Retention(RetentionPolicy.SOURCE)
public @interface Override {
}

//见上表
@Documented
@Retention(RetentionPolicy.RUNTIME)
@Target(value={CONSTRUCTOR, FIELD, LOCAL_VARIABLE, METHOD, PACKAGE, PARAMETER, TYPE})
public @interface Deprecated {
}

//见上表
@Target({TYPE, FIELD, METHOD, PARAMETER, CONSTRUCTOR, LOCAL_VARIABLE})
@Retention(RetentionPolicy.SOURCE)
public @interface SuppressWarnings {
    String[] value();
}

 

Guess you like

Origin blog.csdn.net/wishxiaozhu/article/details/114900357