Java Reflection Method Get from Object getMethodResult(final Object element, final String methodName)

Here you can find the source of getMethodResult(final Object element, final String methodName)

Description

get Method Result

License

Mozilla Public License

Declaration

static Object getMethodResult(final Object element, final String methodName) throws Exception 

Method Source Code

//package com.java2s;
/**//ww  w . j  a v a 2s  . c  o m
 * Copyright 2007, Lorenzo Bolzani
 * 
 * The contents of this file are subject to the Mozilla Public License Version
 * 1.1 (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.mozilla.org/MPL/MPL-1.1.html
 **/

import java.lang.reflect.Method;

public class Main {
    static Object getMethodResult(final Object element, final String methodName) throws Exception {
        return getMethodResult(element, methodName, null);
    }

    static Object getMethodResult(final Object element, final String methodName, final Object param)
            throws Exception {

        Class[] classes = null;
        Object[] params = null;
        if (param != null) {
            classes = new Class[] { param.getClass() };
            params = new Object[] { param };
        }

        // TODO: sistemare
        final Method m = element.getClass().getMethod(methodName, classes);
        m.setAccessible(true);
        return m.invoke(element, params);
    }
}

Related

  1. getMethodNamed(String methodName, Object holder)
  2. getMethodNames(Object obj, boolean hasParent)
  3. getMethodNames(Object obj, boolean includeInheritedMethods)
  4. getMethodObject(Class type, Class clazz, String method, Class[] args, Object object, Object[] objects)
  5. getMethodObject(Object object, String method, Object[] parametre)
  6. getMethodReturn(String className, String methodName, Class[] params, Object[] args, boolean isStatic)
  7. getMethodReturnTypeGeneric(Object source, Method method)
  8. getMethods(Class objectClass, Class annotationClass)
  9. getMethods(Object instance, String name, Class[] arguments, boolean isPrefix)