注解的原理
元注解
修饰注解的注解叫元注解
注解解析
如何解析注解
@Target(ElementType.METHOD)
@Retention(RetentionPolicy.RUNTIME)
public @interface LogAnnotation {
String value();
String message();
}
@Test
void name() throws Exception{
Class<User> uClass = User.class;
Method method = uClass.getDeclaredMethod("say", String.class);
boolean present = method.isAnnotationPresent(LogAnnotation.class);
if(present){
LogAnnotation annotation = method.getDeclaredAnnotation(LogAnnotation.class);
String value = annotation.value();
String message = annotation.message();
}
}