/**
* @author 邓聪
*应用在类上的注解
*/
@Target(ElementType.TYPE)
@Retention(RetentionPolicy.RUNTIME)
public @interface Class_anno {
String name() default "congge";
}
//===================================================
/**
* @author 邓聪
*应用在方法上的注解
*/
@Target(ElementType.METHOD)
@Retention(RetentionPolicy.RUNTIME)
public @interface Method_anno {
int i() default 100;
}
//==================================================
/**
* @author 邓聪
* 注解测试(注解处理器)
*
*/
public class Test{
public static void main(String[] args) throws Exception, Exception {
Annota annota = new Annota();
System.out.println(annota.getClass().getAnnotation(Class_anno.class).name());
System.out.println(annota.getClass().getMethod("haha").getAnnotation(Method_anno.class).i());
}
}
//====执行结果=============
congge
100
时间: 2025-01-08 17:30:06