import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.ElementType;
import java.lang.annotation.Target;
import java.lang.reflect.Method;
@Target(ElementType.METHOD)        //添加@Target，指定自定义标识Annotation仅用于标注方法
@Retention(RetentionPolicy.RUNTIME)
public  @interface  MarkerAnnotationTest{
}
class Example12_6{
@MarkerAnnotationTest
public void testMethod() {
   System.out.println("The MarkerAnnotation test.");
} 
public static void main(String[] args){
Class c = TestMain.class;
try{
Method method = c.getMethod("testMethod "); 
//判断method所代表的方法是否添加了自定义标注MarkerAnnotationTest
	 if(method.isAnnotationPresent(MarkerAnnotationTest.class)){
System.out.println("Find Marker Annotation!");
	 }else{
	   System.out.println("No Annotation be found.");
	 }
	 TestMain test = (TestMain)c.newInstance();
	 test.method();
}catch(NoSuchMethodException e){
  System.out.println(e);
}catch(InstantiationException e){
  System.out.println(e);
}catch(IllegalAccessException e){
  System.out.println(e);
}
}
}
