jiangxin369 commented on code in PR #235:
URL: https://github.com/apache/flink-ml/pull/235#discussion_r1178910190


##########
flink-ml-iteration/src/main/java/org/apache/flink/iteration/utils/ReflectionUtils.java:
##########
@@ -80,4 +83,55 @@ public static <T> T callMethod(
                     "Failed to get method" + methodName + " from " + 
targetObject, e);
         }
     }
+
+    /**
+     * The utility method to call method with the specific name and parameters.
+     *
+     * <p>Note that this method is added only for bypassing the existing bug 
in Py4j. It doesn't
+     * validate the classes of parameters so it can only deal with the classes 
that have only one
+     * method with the specific name.
+     *
+     * <p>TODO Remove this method after the Py4j bug is fixed.
+     */
+    @SuppressWarnings("unchecked")
+    public static <T> T callMethodByName(
+            Object targetObject, Class<?> declaredClass, String methodName, 
Object[] parameters) {
+        List<Method> methods = new ArrayList<>();
+        for (Method m : declaredClass.getMethods()) {
+            if (methodName.equals(m.getName())) {
+                m.setAccessible(true);
+                methods.add(m);
+            }
+        }
+        Preconditions.checkState(
+                methods.size() == 1,
+                "Only one method with name %s is permitted to be declared in 
%s",
+                methodName,
+                declaredClass);
+        try {
+            return (T) methods.get(0).invoke(targetObject, parameters);
+        } catch (Exception e) {
+            throw new RuntimeException(
+                    "Failed to invoke method" + methodName + " from " + 
targetObject, e);
+        }
+    }
+
+    /**
+     * The utility method to call method with the specific name.
+     *
+     * <p>TODO Remove this method after the Py4j bug is fixed.
+     */
+    @SuppressWarnings("unchecked")
+    public static <T> T callMethodByName(

Review Comment:
   Would it be better if we keep the logic that is to be removed in a separate 
method? We don't have the need to use the inherited methods except for Py4j, 
right? So we don't have to introduce this change in the existing method.
   
   Based on this reason, I add the method called `callMethodByName(Object 
targetObject, Class<?> declaredClass, String methodName)` to differ from the 
existing `callMethod(Object targetObject, Class<?> declaredClass, String 
methodName)` which has the same parameters. To keep the same naming style in 
the two methods I added, they are all named with `callMethodByName`, and this 
answers your above question.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to