diff options
| author | Kostya <mail@sartin.in> | 2026-07-22 21:50:41 +0000 |
|---|---|---|
| committer | Kostya <mail@sartin.in> | 2026-07-22 21:50:41 +0000 |
| commit | c60b6979d8a90b3af03ed94034277e45271383a1 (patch) | |
| tree | 02a78166c9b13e953566553e13ac45b1deffecfb | |
| parent | 0db72804cabb7303b2a58f1bc5605f0306bca22a (diff) | |
| download | java-course-c60b6979d8a90b3af03ed94034277e45271383a1.tar.gz java-course-c60b6979d8a90b3af03ed94034277e45271383a1.tar.xz java-course-c60b6979d8a90b3af03ed94034277e45271383a1.zip | |
method invocation
| -rw-r--r-- | ex1/src/main/java/reflection/api/ReflectionInvestigator.java | 15 | ||||
| -rw-r--r-- | ex1/target/classes/reflection/api/ReflectionInvestigator.class | bin | 6814 -> 7051 bytes |
2 files changed, 11 insertions, 4 deletions
diff --git a/ex1/src/main/java/reflection/api/ReflectionInvestigator.java b/ex1/src/main/java/reflection/api/ReflectionInvestigator.java index 27e7b44..e16d3d5 100644 --- a/ex1/src/main/java/reflection/api/ReflectionInvestigator.java +++ b/ex1/src/main/java/reflection/api/ReflectionInvestigator.java | |||
| @@ -74,9 +74,16 @@ public class ReflectionInvestigator implements Investigator { | |||
| 74 | 74 | ||
| 75 | @Override | 75 | @Override |
| 76 | public Set<String> getNamesOfAllFieldsIncludingInheritanceChain() { | 76 | public Set<String> getNamesOfAllFieldsIncludingInheritanceChain() { |
| 77 | return Stream.of(classInfo.getDeclaredFields()) | 77 | var fields = new HashSet<String>(); |
| 78 | .map(f -> f.getName()) | 78 | var cursor = classInfo; |
| 79 | .collect(Collectors.toSet()); | 79 | while (cursor != null) { |
| 80 | fields.addAll( | ||
| 81 | Stream.of(classInfo.getDeclaredFields()) | ||
| 82 | .map(f -> f.getName()) | ||
| 83 | .collect(Collectors.toSet())); | ||
| 84 | cursor = cursor.getSuperclass(); | ||
| 85 | } | ||
| 86 | return fields; | ||
| 80 | } | 87 | } |
| 81 | 88 | ||
| 82 | @Override | 89 | @Override |
| @@ -109,7 +116,7 @@ public class ReflectionInvestigator implements Investigator { | |||
| 109 | @Override | 116 | @Override |
| 110 | public Object elevateMethodAndInvoke(String name, Class<?>[] parametersTypes, Object... args) { | 117 | public Object elevateMethodAndInvoke(String name, Class<?>[] parametersTypes, Object... args) { |
| 111 | try { | 118 | try { |
| 112 | var method = classInfo.getMethod(name, parametersTypes); | 119 | var method = classInfo.getDeclaredMethod(name, parametersTypes); |
| 113 | method.setAccessible(true); | 120 | method.setAccessible(true); |
| 114 | return method.invoke(subjectInstance, args); | 121 | return method.invoke(subjectInstance, args); |
| 115 | } catch (IllegalAccessException | InvocationTargetException | NoSuchMethodException e) { | 122 | } catch (IllegalAccessException | InvocationTargetException | NoSuchMethodException e) { |
diff --git a/ex1/target/classes/reflection/api/ReflectionInvestigator.class b/ex1/target/classes/reflection/api/ReflectionInvestigator.class index 79d85a7..18a2f21 100644 --- a/ex1/target/classes/reflection/api/ReflectionInvestigator.class +++ b/ex1/target/classes/reflection/api/ReflectionInvestigator.class | |||
| Binary files differ | |||