-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRefection.java
More file actions
36 lines (31 loc) · 1.19 KB
/
Refection.java
File metadata and controls
36 lines (31 loc) · 1.19 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
package enumStudy;
import java.lang.reflect.Method;
import java.lang.reflect.Type;
import java.util.Set;
import java.util.TreeSet;
enum Explore {HERE, THERE}
public class Refection {
public static Set<String> analyze(Class<?> enumClass) {
System.out.println("-------- Analyzing " + enumClass + "--------");
System.out.println("Interfaces");
for (Type t : enumClass.getGenericInterfaces()) {
System.out.println(t);
}
System.out.println("Base: " + enumClass.getSuperclass());
System.out.println("Methods: ");
Set<String> methods = new TreeSet<String>();
for (Method method : enumClass.getMethods()) {
methods.add(method.getName());
}
System.out.println(methods);
return methods;
}
public static void main(String[] args) {
Set<String> exporeMethods = analyze(Explore.class);
Set<String> enumMethods = analyze(Enum.class);
System.out.println("Explore.contaionsAll(Enum)? " + exporeMethods.containsAll(enumMethods));
System.out.println("Explore.contaionsAll(Enum):");
exporeMethods.removeAll(enumMethods);
System.out.println(exporeMethods);
}
}