Here you can find the source of invoke(Object target, String name, Class[] params, Object[] args)
name
on target
with parameters params
declared in the target
's class using arguments args
.
Parameter | Description |
---|---|
target | target Object. |
name | name of the method. |
params | array of Class of parameters of the method. |
args | array of Object of arguments to the method. |
public static Object invoke(Object target, String name, Class[] params, Object[] args)
//package com.java2s; /* -*- Mode: JDE; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- * * This file is part of the debugger and core tools for the AspectJ(tm) * programming language; see http://aspectj.org * * 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 * either http://www.mozilla.org/MPL/ or http://aspectj.org/MPL/. * * Software distributed under the License is distributed on an "AS IS" basis, * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License * for the specific language governing rights and limitations under the * License./*from www .j av a 2s. c om*/ * * The Original Code is AspectJ. * * The Initial Developer of the Original Code is Xerox Corporation. Portions * created by Xerox Corporation are Copyright (C) 1999-2002 Xerox Corporation. * All Rights Reserved. */ public class Main { /** * Returns the result of invoking the method <code>name</code> * on <code>target</code> with parameters <code>params</code> * declared in the <code>target</code>'s class using arguments * <code>args</code>. * * @param target target Object. * @param name name of the method. * @param params array of Class of parameters of the method. * @param args array of Object of arguments to the method. * @return the result of invoking the method. * @see #invoke(Class,Object,String,Class[],Object[]) */ public static Object invoke(Object target, String name, Class[] params, Object[] args) { return invoke(target.getClass(), target, name, params, args); } /** * Returns the result of invoking the method <code>name</code> * on <code>target</code> with parameters <code>params</code> * declared in the <code>type</code> using arguments * <code>args</code>. * This method handles any errors that arise in doing so. * * @param type type in which the method is declared. * @param target target Object -- null for static methods. * @param name name of the method. * @param params array of Class of parameters of the method. * @param args array of Object of arguments to the method. * @return the result of invoking the method. */ public static Object invoke(Class type, Object target, String name, Class[] params, Object[] args) { try { java.lang.reflect.Method method = type.getDeclaredMethod(name, params); method.setAccessible(true); return method.invoke(target, args); } catch (Exception e) { e.printStackTrace(); //TODO } return null; } }