注解与反射
@Override
public String toString() {
return super.toString();
}
@Deprecated
public static void test(){
System.out.println();
}
@SuppressWarnings("all")
public void test02(){
List list = new ArrayList();
}
//常用的参数
@SuppressWarnings("all")
@SuppressWarnings("unchecked")
@SuppressWarnings(value = {"unchecked", "deprecation"})
//使用的范围
==@Target({TYPE, FIELD, METHOD, PARAMETER, CONSTRUCTOR, LOCAL_VARIABLE})==
作用:负责注解其他注解,Java定义了4个标准的meta-annotation类型,被用来提供对其他annotation类型作为说明
均继承与java.long.annotation
public class Test02 {
@MyAnnotation
public void Test02(){
}
}
//对注解的约束,定义只在类中使用,其他地方则会标红报错
@Target(value = ElementType.METHOD)
@interface MyAnnotation{
}
//使用范围(源码解释)
public enum ElementType {
/** Class, interface (including annotation type), or enum declaration */
TYPE,
/** Field declaration (includes enum constants) */
FIELD,
/** Method declaration */
METHOD,
/** Formal parameter declaration */
PARAMETER,
/** Constructor declaration */
CONSTRUCTOR,
/** Local variable declaration */
LOCAL_VARIABLE,
/** Annotation type declaration */
ANNOTATION_TYPE,
/** Package declaration */
PACKAGE,
/**
* Type parameter declaration
*
* @since 1.8
*/
TYPE_PARAMETER,
/**
* Use of a type
*
* @since 1.8
*/
TYPE_USE
}
@Retention(value = RetentionPolicy.SOURCE)
@Retention(value = RetentionPolicy.CLASS)
@Retention(value = RetentionPolicy.RUNTIME)
@Documented:说明该注解被包含在javadoc中
@Inherited:说明子类可以继承父类中的该注解

浙公网安备 33010602011771号