@TestAnnotation(msg="hello")
public void testMethod(){}
@SuppressWarnings("deprecation")
public static void main(String[] args) {
boolean hasAnnotation = Test.class.isAnnotationPresent(TestAnnotation.class);
TestAnnotation testAnnotation = Test.class.getAnnotation(TestAnnotation.class);
System.out.println("id:"+testAnnotation.id());
System.out.println("msg:"+testAnnotation.msg());
Field a = Test.class.getDeclaredField("a");
Check check = a.getAnnotation(Check.class);
System.out.println("check value:"+check.value());
Method testMethod = Test.class.getDeclaredMethod("testMethod");
if ( testMethod != null ) {
Annotation[] ans = testMethod.getAnnotations();
for( int i = 0;i < ans.length;i++) {
System.out.println("method testMethod annotation:"+ans[i].annotationType().getSimpleName());
} catch (NoSuchFieldException e) {
// TODO Auto-generated catch block
System.out.println(e.getMessage());
} catch (SecurityException e) {
// TODO Auto-generated catch block
System.out.println(e.getMessage());
} catch (NoSuchMethodException e) {
// TODO Auto-generated catch block
System.out.println(e.getMessage());