Package org.pipservices3.commons.reflect
Class MethodReflector
java.lang.Object
org.pipservices3.commons.reflect.MethodReflector
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 Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptiongetMethodNames
(Object obj) Gets names of all methods implemented in specified object.static boolean
Checks if object has a method with specified name..static Object
invokeMethod
(Object obj, String name, Object... args) Invokes an object method by its name with specified parameters.
-
Constructor Details
-
MethodReflector
public MethodReflector()
-
-
Method Details
-
hasMethod
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
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
Gets names of all methods implemented in specified object.- Parameters:
obj
- an objec to introspect.- Returns:
- a list with method names.
-