package Test;
import java.lang.reflect.Method;
@person2(Integer_value = 0, b = 0)
public class Annotation {
@person(Integer_value = 12, b = 12, value = "method1")
public void method1(){
}
@person(Integer_value = 24, b = 123, value = "method2")
public void method2(){
}
@person(Integer_value = 0, b = 0,value ="method3")
public void method3(){
}
public static void main(String[] args){
// TODO Auto-generated method stub
Class c=Annotation.class;
Method[] m=c.getMethods();
for(Method t:m){
if(t.isAnnotationPresent(person.class)){
person name=t.getAnnotation(person.class);
System.out.println(name.value());
System.out.println(name.b());
System.out.println(name.Integer_value());
}
}
Class cc=Annotation.class;
System.out.println(c.getAnnotation(person2.class));
class ext extends Annotation{
public void method3(){
}
}
Class e=ext.class;
Method[] me=e.getMethods();
for(Method t:me){
if(t.isAnnotationPresent(person.class)){
person name=t.getAnnotation(person.class);
System.out.println(name.value());
System.out.println(name.b());
System.out.println(name.Integer_value());
}
}
}
}
输出结果
method1
12
12
method2
123
24
method3
0
0
@Test.person2(value=def, Integer_value=0, b=0)
method1
12
12
method2
123
24