-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathSingle.java
More file actions
30 lines (26 loc) · 767 Bytes
/
Single.java
File metadata and controls
30 lines (26 loc) · 767 Bytes
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
package chapter12;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.reflect.Method;
//A single member annotation
@Retention(RetentionPolicy.RUNTIME)
@interface MySingle {
int value();
//int xyz() default 50;
}
public class Single {
@MySingle(value = 100)
public static void myMeth() {
Single ob = new Single();
try {
Method m = ob.getClass().getMethod("myMeth");
MySingle anno = m.getAnnotation(MySingle.class);
System.out.println(anno.value());//displays 100
} catch (NoSuchMethodException e) {
System.out.println("Method Not Found");
}
}
public static void main(String[] args) {
myMeth();
}
}