blob: 3084eb890f7b16af7ca4323063a01974a85fe691 (
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
37
38
39
40
|
import java.lang.annotation.*;
import java.lang.annotation.RetentionPolicy;
@Retention(RetentionPolicy.RUNTIME)
@interface Anno {
String foo();
}
public aspect WithValues {
@Anno(foo="anc")
int i;
declare @field: int i: -@Anno;
declare @field: int j: @Banno(hoo="abc");
int j;
public static void main(String[] args) throws Exception {
if (WithValues.class.getDeclaredField("i").getAnnotation(Anno.class)==null) {
System.out.println("i does not have Anno");
} else {
System.out.println("i has Anno");
}
Annotation a = WithValues.class.getDeclaredField("j").getAnnotation(Banno.class);
if (a==null) {
System.out.println("j does not have Banno");
} else {
System.out.println("j has Banno:"+a);
}
a = WithValues.class.getDeclaredField("j").getAnnotation(Anno.class);
if (a==null) {
System.out.println("j does not have Anno");
} else {
System.out.println("j has Anno:"+a);
}
}
}
@Retention(RetentionPolicy.RUNTIME)
@interface Banno {
String hoo();
}
|