-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMain2.java
More file actions
37 lines (30 loc) · 1.05 KB
/
Copy pathMain2.java
File metadata and controls
37 lines (30 loc) · 1.05 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
package aReflection;
import java.beans.BeanInfo;
import java.beans.Introspector;
import java.beans.PropertyDescriptor;
import java.lang.reflect.Method;
import java.lang.reflect.Modifier;
import java.util.Arrays;
public class Main2 {
public static void main(String[] args) throws Exception {
Student s = new Student();
Class cls = s.getClass();
Method m = cls.getMethod("setAddress", String.class);
printMethodInfo(m);
m.invoke(s, "shanghai");
System.out.println(s.hello());
BeanInfo bi = Introspector.getBeanInfo(cls);
for (PropertyDescriptor pb : bi.getPropertyDescriptors()){
System.out.println(pb.getName());
System.out.println(pb.getReadMethod());
System.out.println(pb.getWriteMethod());
}
}
private static void printMethodInfo(Method m) {
System.out.println(m);
System.out.println("method name: " + m.getName());
System.out.println("return type: " + m.getReturnType());
System.out.println("parameters: " + Arrays.toString(m.getParameterTypes()));
System.out.println("method modifier? : " + m.getModifiers());
}
}