From c60b6979d8a90b3af03ed94034277e45271383a1 Mon Sep 17 00:00:00 2001 From: Kostya Date: Wed, 22 Jul 2026 21:50:41 +0000 Subject: method invocation --- .../main/java/reflection/api/ReflectionInvestigator.java | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) (limited to 'ex1/src/main/java/reflection/api') 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 { @Override public Set getNamesOfAllFieldsIncludingInheritanceChain() { - return Stream.of(classInfo.getDeclaredFields()) - .map(f -> f.getName()) - .collect(Collectors.toSet()); + var fields = new HashSet(); + var cursor = classInfo; + while (cursor != null) { + fields.addAll( + Stream.of(classInfo.getDeclaredFields()) + .map(f -> f.getName()) + .collect(Collectors.toSet())); + cursor = cursor.getSuperclass(); + } + return fields; } @Override @@ -109,7 +116,7 @@ public class ReflectionInvestigator implements Investigator { @Override public Object elevateMethodAndInvoke(String name, Class[] parametersTypes, Object... args) { try { - var method = classInfo.getMethod(name, parametersTypes); + var method = classInfo.getDeclaredMethod(name, parametersTypes); method.setAccessible(true); return method.invoke(subjectInstance, args); } catch (IllegalAccessException | InvocationTargetException | NoSuchMethodException e) { -- cgit v1.2.3