Java Method Call invokeSimple(Object target, String name)

Here you can find the source of invokeSimple(Object target, String name)

Description

invoke Simple

License

Open Source License

Declaration

public static Object invokeSimple(Object target, String name) throws Exception 

Method Source Code

//package com.java2s;
/**//from  w  w  w.  j a v  a 2  s . c o  m
 * The MIT License (MIT)
 * Copyright (c) 2009-2015 HONG LEIMING
 * 
 * Permission is hereby granted, free of charge, to any person obtaining a copy
 * of this software and associated documentation files (the "Software"), to deal
 * in the Software without restriction, including without limitation the rights
 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
 * copies of the Software, and to permit persons to whom the Software is
 * furnished to do so, subject to the following conditions:
 * 
 * The above copyright notice and this permission notice shall be included in
 * all copies or substantial portions of the Software.
 * 
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
 * THE SOFTWARE.
 */

import java.lang.reflect.Method;

public class Main {
    public static Object invokeSimple(Object target, String name) throws Exception {
        Method m = target.getClass().getMethod(name);
        if (m == null) {
            throw new IllegalArgumentException("method:(" + name + ") not found");
        }
        return m.invoke(target);
    }
}

Related

  1. invokeRestrictedMethod(Object obj, Class theClass, String methodName)
  2. invokeServiceClass(JsonReader jsonReader, Object service, Method operation, Class[] paramClasses, int paramCount)
  3. invokeSet(Object o, String fieldName, Object value)
  4. invokeSetFieldValue(Object bean, Field field, Object value)
  5. invokeSilent(Object obj, String methodName, Class[] parameterTypes, Object[] args)
  6. invokeTarget(Method method, Object obj, Object... args)
  7. invokeTargetCheckPoint(String resuming_checkpoint_path, Object jobObject, final java.util.Map globalMap)
  8. invokeTargetMethods(Object obj, T data, List methods)
  9. invokeToStringMethod(Object value, Class type)