/**循环向上转型,获取对象的的DeclaredMethod
* @param object
* @param methodname
* @param parameterTypes
* @return
*/
public static Method getDeclaredMethod(Object object, String methodname, Class<?>[] parameterTypes){
for (Class<?> superClass = object.getClass(); superClass != Object.class;
superClass = superClass.getSuperclass()) {
try {
//
return superClass.getDeclaredMethod(methodname, parameterTypes);
} catch (NoSuchMethodException e) {
//method 不在当前类定义,继续向上转型
}
}
return null;
}
相关分类