Java
IntelliJ IDEA
先来看看JDK自带的三个注解:OverrideDeprecatedSuppressWarnings注意上面的是Annotation Type注解也是一种数据类型哦
先来看看Override,注解声明注解关键词是@interface哦@Target(ElementType.METHOD)//此注解可以在方法上使用@Retention(RetentionPolicy.SOURCE)//此注解在源码中有效。编译器不处理public @interface Override {}
Deprecated@Documented//Indicates that annotations with a type are to be //documented by javado and similar tools by default@Retention(RetentionPolicy.RUNTIME)//这个注解会一直保留到jvm中。使用 //gradle编译代码时,如果使用了被标 //记为@Deprecated时,会提示的public @interface Deprecated {}
SuppressWarnings@Target({TYPE, FIELD, METHOD, PARAMETER, CONSTRUCTOR, LOCAL_VARIABLE})@Retention(RetentionPolicy.SOURCE)public @interface SuppressWarnings { /** * The set of warnings that are to be suppressed by the compiler in the * annotated element. Duplicate names are permitted. The second and * successive occurrences of a name are ignored. The presence of * unrecognized warning names is not an error: Compilers must * ignore any warning names they do not recognize. They are, however, * free to emit a warning if an annotation contains an unrecognized * warning name. * *
Compiler vendors should document the warning names they support in * conjunction with this annotation type. They are encouraged to cooperate * to ensure that the same names work across multiple compilers. */ String[] value();}
SupressWarnings比较特殊,源码也比较长,就多说两句@Target({TYPE, FIELD, METHOD, PARAMETER, CONSTRUCTOR, LOCAL_VARIABLE})可以使用的场景比较多,直接来看看ElementType中各个值代码的含义public enum ElementType { /** Class, interface (including annotation type), or enum declaration */ TYPE, /** Field declaration (includes enum constants) */ FIELD, /** Method declaration */ METHOD, /** Parameter declaration */ PARAMETER, /** Constructor declaration */ CONSTRUCTOR, /** Local variable declaration */ LOCAL_VARIABLE, /** Annotation type declaration */ ANNOTATION_TYPE, /** Package declaration */ PACKAGE}
方法名就是参数名(在java代码中使用注解时的key);返回值类型就是参数的类型(返回值类型只能是基本类型、Class、String、enum);返回值就是取值范围;来看看SupressWarnings的取值范围Fortunately for us, the Eclipse folks have documented the values they support (As of Eclipse 3.3), here they are for reference:all to suppress all warningsboxing to suppress warnings relative to boxing/unboxing operationscast to suppress warnings relative to cast operationsdep-ann to suppress warnings relative to deprecated annotationdeprecation to suppress warnings relative to deprecationfallthrough to suppress warnings relative to missing breaks in switch statementsfinally to suppress warnings relative to finally block that don’t returnhiding to suppress warnings relative to locals that hide variableincomplete-switch to suppress warnings relative to missing entries in a switch statement (enum case)nls to suppress warnings relative to non-nls string literalsnull to suppress warnings relative to null analysisrawtypes to suppress warnings relative to un-specific types when using generics on class paramsrestriction to suppress warnings relative to usage of discouraged or forbidden referencesserial to suppress warnings relative to missing serialVersionUID field for a serializable classstatic-access to suppress warnings relative to incorrect static accesssynthetic-access to suppress warnings relative to unoptimized access from inner classesunchecked to suppress warnings relative to unchecked operationsunqualified-field-access to suppress warnings relative to field access unqualifiedunused to suppress warnings relative to unused codeTIP: For the folks that haven’t used @SuppressWarnings before, the syntax looks like this: