/**
* Copyright By suren.
* You can get more information from my website:
* http://surenpi.com
*/
package org.suren.annotation;
import java.lang.annotation.Annotation;
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
import java.lang.reflect.Field;
import java.lang.reflect.Method;
import java.util.Arrays;
/**
* @author suren
* @date 2015年10月12日 上午10:16:41
*/
@SuRenAnnotation(value = "good")
@SuRenAnnotationA
public class Tester
{
@SuRenAnnotationA
private String name;
/**
* @param args
*/
public static void main(String[] args) throws Exception
{
System.out.println(Arrays.toString(Tester.class.getAnnotations()));
System.out.println(Arrays.toString(Tester.class.getDeclaredAnnotations()));
for(Field field : Tester.class.getDeclaredFields()){
System.out.println(Arrays.toString(field.getAnnotations()));
}
for(Annotation annotation : Tester.class.getAnnotations()){
for(Method method : annotation.annotationType().getDeclaredMethods()){
if(method.getName().equals("value")){
System.out.println(method.invoke(annotation));
}
}
}
}
}
@Retention(RetentionPolicy.RUNTIME)
@Target({ElementType.TYPE})
@interface SuRenAnnotation
{
String value() default "suren";
}
@Retention(RetentionPolicy.RUNTIME)
@Target({ElementType.FIELD, ElementType.TYPE})
@interface SuRenAnnotationA
{
}
@interface SuRenAnnotationB{
}