-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAnnotation1.java
More file actions
36 lines (27 loc) · 913 Bytes
/
Annotation1.java
File metadata and controls
36 lines (27 loc) · 913 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
34
35
36
import com.sun.istack.internal.NotNull;
import java.lang.annotation.Annotation;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
public class Annotation1{
@Retention(RetentionPolicy.RUNTIME)
@interface Info{
String name() default "N/A";
int age();
}
@Info(name="Sanil Khurana", age=18)
Annotation1(@NotNull String a){
}
@Info(name="Sanil2", age = 21)
public void getAnnotationsUsingReflections(){
try{
Class c=this.getClass();
Info info=c.getMethod("getAnnotationsUsingReflections").getAnnotation(Info.class);
System.out.print(info);
}catch (Exception e){
}
}
public static void main(String[] args){
Annotation1 annotation1 = new Annotation1(null);
annotation1.getAnnotationsUsingReflections();
}
}