blob: 9fa6a4a9adaf2525b8e1d232eff0ec4f82da5561 (
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
|
import java.lang.annotation.Annotation;
import java.lang.reflect.Field;
public class Hello2 {
public static int i;
public static void main(String[] args) {
printAnnos("i");
}
public static void printAnnos(String fieldname) {
try {
Field m = Hello2.class.getDeclaredField(fieldname);
Annotation[] annos = m.getAnnotations();
System.out.println("Annotations on "+fieldname+"? "+(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();
}
}
}
|