Java Method Call invokeGetMethodWithSameName(Object object, Method method)

Here you can find the source of invokeGetMethodWithSameName(Object object, Method method)

Description

invoke Get Method With Same Name

License

Open Source License

Declaration

private static Object invokeGetMethodWithSameName(Object object, Method method) throws Exception 

Method Source Code

//package com.java2s;
/*******************************************************************************
 * Copyright (C) 2011 by Michael Gerber//from ww w.  jav a  2  s. com
 * 
 * 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 {
    private static Object invokeGetMethodWithSameName(Object object, Method method) throws Exception {
        String methodName = "get" + method.getName().substring(3);
        Method getMethod = object.getClass().getMethod(methodName, new Class[0]);
        return getMethod.invoke(object, new Object[0]);
    }
}

Related

  1. invokeFunction(Object iFunction, String funcName, String param)
  2. invokeFunctions(Object iFunction, String funcName)
  3. invokeGenericMethodOneArg(final Object obj, final String methodName, final Object arg)
  4. invokeGet(Object o, String fieldName)
  5. invokeGetClasspathMethodIfItExists(ClassLoader cl)
  6. invokeHeritedMethod(Object target, String method, Class klass)
  7. invokeInstanceMethod(Object target, String methodName, Class type, Object arg)
  8. invokeIteratorCallable(String callableClassName, ClassLoader cl)
  9. invokeMXMethod(String methodName)