Java Method Call invoke(Object obj, String methodName, boolean newValue)

Here you can find the source of invoke(Object obj, String methodName, boolean newValue)

Description

invoke

License

Open Source License

Declaration

public static Object invoke(Object obj, String methodName, boolean newValue) throws NoSuchMethodException 

Method Source Code

//package com.java2s;
//License from project: Open Source License 

import java.lang.reflect.Method;
import java.lang.reflect.InvocationTargetException;

public class Main {
    public static Object invoke(Object obj, String methodName, boolean newValue) throws NoSuchMethodException {
        try {/*from w  ww.ja v a2 s.c  o  m*/
            Method method = obj.getClass().getMethod(methodName, new Class[] { Boolean.TYPE });
            return method.invoke(obj, new Object[] { new Boolean(newValue) });
        } catch (IllegalAccessException e) {
            throw new NoSuchMethodException(methodName + " is not accessible");
        } catch (InvocationTargetException e) {
            // The method is not supposed to throw exceptions
            throw new InternalError(e.getMessage());
        }
    }

    public static Object invoke(Object obj, String methodName, int newValue) throws NoSuchMethodException {
        try {
            Method method = obj.getClass().getMethod(methodName, new Class[] { Integer.TYPE });
            return method.invoke(obj, new Object[] { new Integer(newValue) });
        } catch (IllegalAccessException e) {
            throw new NoSuchMethodException(methodName + " is not accessible");
        } catch (InvocationTargetException e) {
            // The method is not supposed to throw exceptions
            throw new InternalError(e.getMessage());
        }
    }

    public static Object invoke(Object obj, String methodName, float newValue) throws NoSuchMethodException {
        try {
            Method method = obj.getClass().getMethod(methodName, new Class[] { Float.TYPE });
            return method.invoke(obj, new Object[] { new Float(newValue) });
        } catch (IllegalAccessException e) {
            throw new NoSuchMethodException(methodName + " is not accessible");
        } catch (InvocationTargetException e) {
            // The method is not supposed to throw exceptions
            throw new InternalError(e.getMessage());
        }
    }
}

Related

  1. invoke(Object obj, Method method, Object[] params)
  2. invoke(Object obj, String method, Class[] params, Object[] args)
  3. invoke(Object obj, String method, Class[] params, Object[] args)
  4. invoke(Object obj, String method, Object param, Object paramType)
  5. invoke(Object obj, String methodName)
  6. invoke(Object obj, String methodName, Class argType, Object arg)
  7. invoke(Object obj, String methodName, Class clazz, Object newValue)
  8. invoke(Object obj, String methodName, Class[] parameterTypes, Object[] args)
  9. invoke(Object obj, String methodName, Object... args)