get Methods Named - Java Reflection

Java examples for Reflection:Method Name

Description

get Methods Named

Demo Code


//package com.java2s;

import java.lang.reflect.Method;

import java.util.LinkedList;
import java.util.List;

public class Main {
    public static void main(String[] argv) throws Exception {
        String methodName = "java2s.com";
        Object obj = "java2s.com";
        System.out.println(getMethodsNamed(methodName, obj));
    }//  w w  w.  j a v  a2s.c  o m

    public static List<Method> getMethodsNamed(String methodName, Object obj) {
        Method[] methods = obj.getClass().getDeclaredMethods();
        List<Method> methodList = new LinkedList<Method>();
        for (Method method : methods) {
            if (method.getName().equals(methodName))
                methodList.add(method);
        }
        return methodList;
    }
}

Related Tutorials