-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathReflection.java
More file actions
45 lines (37 loc) · 1.04 KB
/
Reflection.java
File metadata and controls
45 lines (37 loc) · 1.04 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
package JavaLangPackage;
import java.lang.reflect.Constructor;
import java.lang.reflect.Field;
import java.lang.reflect.Method;
import java.lang.reflect.Parameter;
class MyClass{
private int a;
protected int b;
public int c;
int d;
public MyClass(){}
public MyClass(int x, int y){}
public void display(String m){}
public boolean isTrue(int t, String s, boolean h){return true;}
}
public class Reflection {
public static void main(String[] args) {
Class c = MyClass.class;
System.out.println(c.getName());
Field[] f = c.getDeclaredFields();
for (Field fa: f) {
System.out.println(fa);
}
Constructor[] cons = c.getConstructors();
for (Constructor ct:cons){
System.out.println(ct);
}
Method[] meth = c.getMethods();
for(Method met: meth){
System.out.println(met);
}
Parameter[] param = meth[1].getParameters();
for (Parameter p:param) {
System.out.println(p);
}
}
}