forked from JavaOPs/basejava
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMainReflection.java
More file actions
29 lines (24 loc) · 965 Bytes
/
MainReflection.java
File metadata and controls
29 lines (24 loc) · 965 Bytes
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
package ru.javaops.webapp;
import ru.javaops.webapp.model.Resume;
import java.lang.reflect.Field;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
public class MainReflection {
@SuppressWarnings("unchecked")
public static void main(String[] args) throws IllegalAccessException {
Resume r = new Resume("dummy");
Field field = r.getClass().getDeclaredFields()[0];
field.setAccessible(true);
System.out.println(field.getName());
System.out.println(field.get(r));
field.set(r, "new_uuid");
System.out.println(r);
Class resumeClass = Resume.class;
try {
Method method = resumeClass.getDeclaredMethod("toString", (Class<?>[]) null);
System.out.println(method.invoke(r, (Object[]) null));
} catch (NoSuchMethodException | InvocationTargetException e) {
System.out.println(e.getMessage());
}
}
}