-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathClassViewer.java
More file actions
38 lines (33 loc) · 1.11 KB
/
Copy pathClassViewer.java
File metadata and controls
38 lines (33 loc) · 1.11 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
package reflection;
import java.lang.reflect.Constructor;
import java.lang.reflect.Field;
import java.lang.reflect.Method;
public class ClassViewer {
public static void showClassInfo(String classAbsName) {
try {
Class<?> clazz = Class.forName(classAbsName);
System.out.println("class name: " + clazz.getCanonicalName());
Constructor<?>[] constructors = clazz.getConstructors();
System.out.println("class constructors:");
for (Constructor<?> constructor : constructors) {
System.out.println("\t" + constructor);
}
Field[] fields = clazz.getDeclaredFields();
System.out.println("class declared fields:");
for (Field field : fields) {
System.out.println("\t" + field);
}
Method[] methods = clazz.getDeclaredMethods();
System.out.println("class declared methods:");
for (Method method : methods) {
System.out.println("\t" + method);
}
} catch (ClassNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
public static void main(String[] args) {
ClassViewer.showClassInfo("java.util.ArrayList");
}
}