getMethod
public
Method getMethod(
String name,
Class... parameterTypes)
throws
NoSuchMethodException,
SecurityException Returns a Method object that reflects the specified public member method of the class or interface represented by this Class object. The name parameter is a String specifying the simple name the desired method. The parameterTypes parameter is an array of Class objects that identify the method's formal parameter types, in declared order. If parameterTypes is null, it is treated as if it were an empty array. If the name is "<init>"or "<clinit>" a NoSuchMethodException is raised. Otherwise, the method to be reflected is determined by the algorithm that follows. Let C be the class represented by this object:
- C is searched for any matching methods. If no matching method is found, the algorithm of step 1 is invoked recursively on the superclass of C.
- If no method was found in step 1 above, the superinterfaces of C are searched for a matching method. If any such method is found, it is reflected.
To find a matching method in a class C: If C declares exactly one public method with the specified name and exactly the same formal parameter types, that is the method reflected.
If more than one such method is found in C, and one of these methods has a return type that is more specific than any of the others, that method is reflected; otherwise one of the methods is chosen arbitrarily. See
The Java Language Specification, sections 8.2 and 8.4.
Parameters:name - the name of the methodparameterTypes - the list of parameters
Returns:the Method object that matches the specified name and parameterTypes
Throws: NoSuchMethodException - if a matching method is not found or if the name is "<init>"or "<clinit>".
NullPointerException - if name is null
SecurityException - If a security manager,
s, is present and any of the following conditions is met:
Since:JDK1.1
Partager