Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
 package de.zalando.sprocwrapper.globalvaluetransformer;
 
 
 import java.util.List;
 
 
public class ReflectionUtils {

    
Attempt to find exactly one java.lang.reflect.Method on the supplied class with the supplied name Searches all superclasses up to Object.

Returns null if no java.lang.reflect.Method can be found.

Parameters:
clazz the class to introspect
name the name of the method
paramTypes the parameter types of the method (may be null to indicate any signature)
Returns:
the Method object, or null if none found
    public static Method findMethod(final Class<?> clazzfinal String name) {
        Assert.notNull(clazz"Class must not be null");
        Assert.notNull(name"Method name must not be null");
        Class<?> searchType = clazz;
        final List<MethodfoundMethods = Lists.newArrayList();
        while (searchType != null && !searchType.isInterface() && !Modifier.isAbstract(searchType.getModifiers())) {
            final Method[] methods = searchType.getDeclaredMethods();
            for (final Method method : methods) {
                if (name.equals(method.getName()) && !method.isSynthetic() && !method.isBridge()) {
                    foundMethods.add(method);
                }
            }
            searchType = searchType.getSuperclass();
        }
        if (foundMethods.isEmpty()) {
            return null;
        }
        if (foundMethods.size() > 1) {
            throw new IllegalArgumentException("The class " + clazz + " contains more than one methods with name "
                    + name);
        }
        return foundMethods.get(0);
    }
New to GrepCode? Check out our FAQ X