Returns an array of Method objects that represent all of the public methods (either declared or inherited) supported by the target Class object Returns a Method object that represents a public method (either declared or inherited) of the target Class object with the signature specified by the second parameters Table 1.1 The methods defined by Class for method query Method This seems fine for methods that take objects as parameters, but what about types not created by a class declaration? For example, getMethod from listing 1 uses an array of Class to indicate the types of the parameters of the desired method. The discussion of the methods from table 1 indicates that Java reflection uses instances of Class to represent types. Would match a boolean primitive.Editor’s Note: This piece picks up where the article Java Reflection in Action left off.] 1.5 Representing types with class objects invokeStaticMethod public static Object invokeStaticMethod( Class cls,.Method invoked IllegalAccessException - if the requested method is not accessible Parameters: cls - invoke static method on this class methodName - get method with this name args - use these arguments - treat null as empty array Returns: The value returned by the invoked method Throws: NoSuchMethodException - if there is no such accessible method InvocationTargetException - wraps an exception thrown by the InvokeStaticMethod(Class, String, Object, Class). Invokes a named static method whose parameter type matches the object type. Parameters: object - invoke method on this object forceAccess - force access to invoke method even if it's not accessible methodName - get method with this name args - use these arguments - treat null as empty array parameterTypes - match these parameters - treat null as empty array Returns: The value returned by the invoked method Throws: NoSuchMethodException - if there is no such accessible method InvocationTargetException - wraps an exception thrown by the method invoked IllegalAccessException - if the requested method is not accessible via reflection Since: 3.5 Parameters: object - invoke method on this object forceAccess - force access to invoke method even if it's not accessible methodName - get method with this name args - use these arguments - treat null as empty array Returns: The value returned by the invoked method Throws: NoSuchMethodException - if there is no such accessible method InvocationTargetException - wraps an exception thrown by the method invoked IllegalAccessException - if the requested method is not accessible via reflection Since: 3.5 InvokeMethod(Object object, boolean forceAccess, String methodName, Object args, Class parameterTypes). invokeMethod public static Object invokeMethod( Object object,.Parameters: object - invoke method on this object methodName - get method with this name args - use these arguments - treat null as empty array Returns: The value returned by the invoked method Throws: NoSuchMethodException - if there is no such accessible method InvocationTargetException - wraps an exception thrown by the method invoked IllegalAccessException - if the requested method is not accessible via reflection InvokeMethod(Object object, String methodName, Object args, Class parameterTypes). This method supports calls to methods taking primitive parameters This method delegates the method search to getMatchingAccessibleMethod(Class, String, Class). Invokes a named method whose parameter type matches the object type.
0 Comments
Leave a Reply. |