-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAnnotationTest.java
More file actions
67 lines (51 loc) · 1.32 KB
/
Copy pathAnnotationTest.java
File metadata and controls
67 lines (51 loc) · 1.32 KB
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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
package annotation.java;
import org.junit.Test;
import java.lang.annotation.Annotation;
import java.util.ArrayList;
public class AnnotationTest {
public static void main(String[] args) {
Student student = new Student();
student.walk();
@SuppressWarnings({"unused","rawtypes"})
ArrayList list = new ArrayList();
}
@Test
public void getAnnotation(){
Class<Student> clazz = Student.class;
Annotation[] annotations = clazz.getAnnotations();
for (int i = 0; i < annotations.length ; i++) {
System.out.println(annotations[i]); // @annotation.java.MyAnnotation(value=Hi)
}
}
}
@MyAnnotation(value = "Hi")
class Person{
private String name;
private int age;
@MyAnnotation
public Person() {
}
@MyAnnotation
public Person(String name, int age) {
this.name = name;
this.age = age;
}
@MyAnnotation
public void walk(){
System.out.println("person is walking");
}
@MyAnnotation
public void sleep(){
System.out.println("person is sleeping");
}
}
class Student extends Person{
@Override
public void walk() {
System.out.println("student is walking");
}
@Override
public void sleep() {
System.out.println("student is sleeping");
}
}