개발하자/JSP&Servlet
getDeclaredMethod,getAnnotation
i구야
2015. 3. 28. 11:04
import java.lang.annotation.*;
import java.lang.reflect.*;
@Target(value={ElementType.METHOD,ElementType.TYPE})
@Retention(value=RetentionPolicy.RUNTIME)
@interface DD{
int a();
String b() default "bbb";
int[] c() default {600,700};
}
@DD(a=100,b="aaa",c={200,300,400})
class B{
@DD(a=500)
void d(){
System.out.println("메서드");
}
public static void main(String args[]) throws Exception{
Method m=B.class.getDeclaredMethod("d");
DD o=m.getAnnotation(DD.class);
int v1=o.a();
System.out.println(v1); //500출력
}
}