Here you can find the source of getMethod(Object obj, String name, Class... types)
Parameter | Description |
---|---|
obj | The object |
name | name of method to pull from the project |
types | argument types |
Parameter | Description |
---|---|
IllegalArgumentException | an exception |
IllegalAccessException | an exception |
NoSuchMethodException | an exception |
public static Method getMethod(Object obj, String name, Class... types) throws IllegalArgumentException, IllegalAccessException, NoSuchMethodException
//package com.java2s; /******************************************************************************* * Copyright (c) 2013 WPI-Suite/*from w w w . j a va 2 s . co m*/ * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at * http://www.eclipse.org/legal/epl-v10.html * * Contributors: Team YOCO (You Only Compile Once) ******************************************************************************/ import java.lang.reflect.Method; public class Main { /** * Easy way to get accessible methods from inherited children * @param obj The object * @param name name of method to pull from the project * @param types argument types * @return accessible method * @throws IllegalArgumentException * @throws IllegalAccessException * @throws NoSuchMethodException */ public static Method getMethod(Object obj, String name, Class... types) throws IllegalArgumentException, IllegalAccessException, NoSuchMethodException { Class c = obj.getClass(); while (c != Object.class) { try { Method m = c.getDeclaredMethod(name, types); m.setAccessible(true); return m; } catch (NoSuchMethodException e) { c = c.getSuperclass(); } } throw new NoSuchMethodException(name); } }