-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathMarker.java
More file actions
33 lines (26 loc) · 792 Bytes
/
Marker.java
File metadata and controls
33 lines (26 loc) · 792 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
31
32
33
package chapter12;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.reflect.Method;
//A marker annotation
@Retention(RetentionPolicy.RUNTIME)
@interface MyMarker {
}
public class Marker {
//Annotate a method using a marker
@MyMarker
public static void myMeth() {
Marker ob = new Marker();
try {
Method m = ob.getClass().getMethod("myMeth");
//Determine if the annotation is present
if (m.isAnnotationPresent(MyMarker.class))
System.out.println("My Marker is Present");
} catch (NoSuchMethodException e) {
System.out.println("Method not found.");
}
}
public static void main(String[] args) {
myMeth();
}
}