aboutsummaryrefslogtreecommitdiffstats
path: root/tests/bugs170/xmldefs/Hello.java
blob: fdf29eab3a2ac20c90015371c64455f9b52274e4 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
import java.lang.annotation.Annotation;
import java.lang.reflect.Method;

public class Hello {

        public static void main(String[] args) {
                sayHello();
                printAnnos("sayHello");
        } 

        public static void sayHello() {
                System.out.println("Hello");
                sayWorld();
        } 

        public static int sayWorld() {
                System.out.println("World");
                return 0;
        }

        public static void printAnnos(String methodname) {
        	try {
	        	Method m = Hello.class.getDeclaredMethod(methodname);
	        	Annotation[] annos = m.getAnnotations();
	        	System.out.println("Annotations on "+methodname+"? "+(annos!=null && annos.length!=0));
	        	if (annos!=null && annos.length>0) {
	        		System.out.println("Annotation count is "+annos.length);
	        		for (Annotation anno: annos) {
	        			System.out.println(anno);
	        		}
	        	}
        	} catch (Exception e) {
        		e.printStackTrace();
        	}
        }
}