Java Reflection Method Invoke invoke(Method m, Object o, String msg, Object... parameters)

Here you can find the source of invoke(Method m, Object o, String msg, Object... parameters)

Description

invoke

License

Apache License

Declaration

static Object invoke(Method m, Object o, String msg, Object... parameters) throws ReflectionException 

Method Source Code

//package com.java2s;
/*/*from w  w w . ja va2  s .co m*/
 * Copyright (c) 2008 Kasper Nielsen.
 *
 * Licensed under the Apache License, Version 2.0 (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.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

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

import javax.management.ReflectionException;

public class Main {
    static Object invoke(Method m, Object o, String msg, Object... parameters) throws ReflectionException {
        try {
            return m.invoke(o, parameters);
        } catch (InvocationTargetException e) {
            Throwable t = e.getTargetException();
            if (t instanceof Error) {
                throw (Error) t;
            }
            throw new ReflectionException((Exception) t, "Exception thrown while invoking  " + msg);
        } catch (IllegalAccessException e) {
            throw new ReflectionException(e, "Illegal access while trying to invoke " + msg);
        }
    }
}

Related

  1. invoke(Method m, Object o, Object[] args)
  2. invoke(Method m, Object target, Object... params)
  3. invoke(Method method)
  4. invoke(Method method)
  5. invoke(Method method, Object data, Object... arguments)