import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
import java.lang.annotation.ElementType;
import java.lang.reflect.Field;
import java.lang.reflect.Method;
@Target(ElementType.FIELD)     //添加@Target，指定自定义标识Annotation仅用于标注成员变量
@Retention(RetentionPolicy.RUNTIME)
public @interface StandardAnnotationTest{
  String name();
}
class AnalyClass{
	public void printInfo(){
		System.out.println("By Stardard Annotation out!");
	}
}
class LoadedClass{
	@StandardAnnotationTest(name="AnalyClass")  //使用自定义Annotation，并为name属性赋值
	public AnalyClass anay;
}
class Example12_7{
	public static void main(String[] args){
		Class c = LoadedClass.class;            //利用反射机制加载LoadedClass类
		try{
        	    Field field = c.getField("anay");
        	    if(field.isAnnotationPresent(StandardAnnotationTest.class)){
StandardAnnotationTest stand = field.getAnnotation(StandardAnnotationTest.class);
String className = stand.name();  //获取自定义标准Annotation中name参数的值
Class temp = Class.forName(className);
Object object = temp.newInstance();
                 //获取printInfo()方法的反射对象
        		   Method method = temp.getDeclaredMethod("printInfo");  
   method.invoke(object);
}
      }catch(Exception e){
         System.out.println(e);
      }
	}
}
