Java Reflection Method Get from Object getMethodsByStartsWithName(String name, Object o)

Here you can find the source of getMethodsByStartsWithName(String name, Object o)

Description

this will get all mehods whose names start with the expressed string

License

Apache License

Parameter

Parameter Description
name a parameter

Declaration

public static Collection<Method> getMethodsByStartsWithName(String name, Object o)
        throws NoSuchMethodException, IllegalAccessException 

Method Source Code

//package com.java2s;
//License from project: Apache License 

import java.lang.reflect.Method;

import java.util.ArrayList;

import java.util.Collection;

public class Main {
    /**// w w w .  ja va2  s  . c o  m
     * this will get all mehods whose names start with the expressed string 
     * @param name
     * @return
     */
    public static Collection<Method> getMethodsByStartsWithName(String name, Object o)
            throws NoSuchMethodException, IllegalAccessException {
        Collection<Method> methods = new ArrayList<Method>();
        Class c = o.getClass();
        java.lang.reflect.Method[] theMethods = c.getMethods();
        for (int i = 0; i < theMethods.length; i++) {
            String methodString = theMethods[i].getName();

            //is this a method we want to use?
            if (methodString.startsWith(name)) {
                methods.add(theMethods[i]);
                Class[] parameterTypes = theMethods[i].getParameterTypes();
            }

        }
        return methods;
    }
}

Related

  1. getMethods(Object obj, boolean hasParent)
  2. getMethods(Object obj, int cmpModifier, String prefix)
  3. getMethodsAnnotatedWith(Class ann, Object o)
  4. getMethodsAnnotatedWith(Object target, Class annotation)
  5. getMethodsAnnotatedWithValue(Class anno, Object o, String name, Object value)
  6. getMethodsForObject(Object o2, String[] passedMethods)
  7. getMethodsIncludingHierarchy(Object comp, Class annotation)
  8. getMethodValue(Method method, Object instance)
  9. getMethodValue(Object base, Method method)