Skip to content

Commit

Permalink
new lower level method invoking
Browse files Browse the repository at this point in the history
  • Loading branch information
n9Mtq4 committed Jun 25, 2015
1 parent 1cb02ab commit 7225d96
Showing 1 changed file with 23 additions and 8 deletions.
31 changes: 23 additions & 8 deletions src/com/n9mtq4/reflection/ReflectionHelper.java
Original file line number Diff line number Diff line change
Expand Up @@ -1465,6 +1465,27 @@ public static <E> E callConstructor(Class clazz, Object... params) {
return callConstructor(clazz, getClassParams(params), params);
}

/**
* Call object method.
*
* @param <E> the type parameter
* @param method the method
* @param obj the obj
* @param params the params
* @return the e
*/
public static <E> E callObjectMethod(Method method, Object obj, Object... params) {
method.setAccessible(true);
try {
return (E) method.invoke(obj, params);
}catch (IllegalAccessException e) {
e.printStackTrace();
}catch (InvocationTargetException e) {
e.printStackTrace();
}
return null;
}

/**
* Call object method.
*
Expand All @@ -1477,17 +1498,11 @@ public static <E> E callConstructor(Class clazz, Object... params) {
* @return the object
*/
public static <E> E callObjectMethod(String methodName, Object obj, Class clazz, Class[] classParams, Object[] params) {
Method m = null;
try {
m = getAllDeclaredMethod(methodName, classParams, clazz);
m.setAccessible(true);
return (E) m.invoke(obj, params);
Method m = getAllDeclaredMethod(methodName, classParams, clazz);
return callObjectMethod(m, obj, params);
}catch (NoSuchMethodException e) {
e.printStackTrace();
}catch (InvocationTargetException e) {
e.printStackTrace();
}catch (IllegalAccessException e) {
e.printStackTrace();
}
return null;
}
Expand Down

0 comments on commit 7225d96

Please sign in to comment.