Java Reflection Method Parameter getMethod(final Field visitee, final String methodName, final Class... parameterTypes)

Here you can find the source of getMethod(final Field visitee, final String methodName, final Class... parameterTypes)

Description

Gets the method specified by methodName for the optionally specified parameterTypes from the specified visitee 's declaring class.

License

Apache License

Parameter

Parameter Description
visitee a parameter
methodName a parameter
parameterTypes a parameter

Return

the method

Declaration

public static Method getMethod(final Field visitee, final String methodName, final Class<?>... parameterTypes) 

Method Source Code


//package com.java2s;
/*/*from w w w.j  av  a2 s .  co m*/
 * Copyright 2013 axn software UG
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

import java.lang.reflect.Field;
import java.lang.reflect.Method;

public class Main {
    /**
     * Gets the method specified by {@code methodName} for the optionally
     * specified {@code parameterTypes} from the specified {@code visitee}'s
     * declaring class.
     *
     * @param visitee
     * @param methodName
     * @param parameterTypes
     * @return the method
     */
    public static Method getMethod(final Field visitee, final String methodName, final Class<?>... parameterTypes) {
        Method result = null;
        try {
            result = visitee.getDeclaringClass().getMethod(methodName, parameterTypes);
        } catch (NoSuchMethodException e) {
            // FIXME:requires more elaborate information for the user
            throw new RuntimeException("Unable to access method " + methodName + " for field:" + visitee.toString(),
                    e);
        }
        return result;
    }
}

Related

  1. getMethod(final Class clazz, final String methodName, final Class... parameterTypes)
  2. getMethod(final Class clazz, final String name, final Class... parametertypes)
  3. getMethod(final Class clazz, final String name, final Class... parameterTypes)
  4. getMethod(final Class target, final String name, final Class... parameters)
  5. getMethod(final Class receiver, final String methodName, final Class... parameterTypes)
  6. getMethod(String classFullName, String methodName, Class... parameterTypes)
  7. getMethod0(Class c, String name, Class... parameterTypes)
  8. getMethod0(Class target, String name, Class[] parameterTypes)
  9. getMethodAnnotations(String className, String methodName, Class[] parameterTypes)