java中元注解有四個(gè):?
@Retention @Target @Document @Inherited抵乓;
@Retention:注解的保留位置
@Retention(RetentionPolicy.SOURCE)?//注解僅存在于源碼中宁仔,在class字節(jié)碼文件中不包含
@Retention(RetentionPolicy.CLASS)?????// 默認(rèn)的保留策略痹束,注解會(huì)在class字節(jié)碼文件中存在齿坷,但運(yùn)行時(shí)無(wú)法獲得,
@Retention(RetentionPolicy.RUNTIME)// 注解會(huì)在class字節(jié)碼文件中存在狐粱,在運(yùn)行時(shí)可以通過(guò)反射獲取到
@Target:注解的作用目標(biāo)
@Target(ElementType.TYPE)?//接口揭措、類、枚舉完慧、注解
@Target(ElementType.FIELD)//字段谋旦、枚舉的常量
@Target(ElementType.METHOD)//方法
@Target(ElementType.PARAMETER)?//方法參數(shù)
@Target(ElementType.CONSTRUCTOR)?//構(gòu)造函數(shù)
@Target(ElementType.LOCAL_VARIABLE)//局部變量
@Target(ElementType.ANNOTATION_TYPE)//注解
@Target(ElementType.PACKAGE)?///包
@Document:說(shuō)明該注解將被包含在javadoc中
@Inherited:說(shuō)明子類可以繼承父類中的該注解