Class MethodReflector

java.lang.Object
org.pipservices3.commons.reflect.MethodReflector

public class MethodReflector extends Object
Helper class to perform method introspection and dynamic invocation.

This class has symmetric implementation across all languages supported by Pip.Services toolkit and used to support dynamic data processing.

Because all languages have different casing and case sensitivity rules, this MethodReflector treats all method names as case insensitive.

### Example ###

 
 MyObject myObj = new MyObject();

 List<String> methods = MethodReflector.getMethodNames();
 MethodReflector.hasMethod(myObj, "myMethod");
 MethodReflector.invokeMethod(myObj, "myMethod", 123);
 
 
  • Constructor Details

    • MethodReflector

      public MethodReflector()
  • Method Details

    • hasMethod

      public static boolean hasMethod(Object obj, String name)
      Checks if object has a method with specified name..
      Parameters:
      obj - an object to introspect.
      name - a name of the method to check.
      Returns:
      true if the object has the method and false if it doesn't.
    • invokeMethod

      public static Object invokeMethod(Object obj, String name, Object... args)
      Invokes an object method by its name with specified parameters.
      Parameters:
      obj - an object to invoke.
      name - a name of the method to invoke.
      args - a list of method arguments.
      Returns:
      the result of the method invocation or null if method returns void.
    • getMethodNames

      public static List<String> getMethodNames(Object obj)
      Gets names of all methods implemented in specified object.
      Parameters:
      obj - an objec to introspect.
      Returns:
      a list with method names.