// Dynamic Proxy나 AOP 대체로 가능할 듯.
(annotation 정의)
import java.lang.annotation.*;
@Inherited
@Documented
@Retention(RetentionPolicy.RUNTIME)
@Target({ ElementType.METHOD })
public @interface MyAnnotation{
String value() default "MyAnnotation";
}
(annotation 적용확인)
import java.lang.reflect.Method;
import MyAnnotation;
public class UseAnnotation{
@MyAnnotation(value="Annotation Test")
public void annotationTest(){
System.out.println("Annotation Method");
}
public static void main(String[] args){
Method[] ms = UseAnnotation.class.getMethods();
for(Method m: methods){
MyAnnotation an = m.getAnnotation(MyAnnotation.class);
if(an != null){
System.out.println("ANNOTATION : "+an.value());
m.invoke(new UseAnnotation(), null);
}
}
}
}