[Java]Javaでrefrection
- April 21st, 2010
- Posted in Java
- Write comment
忘れないようにメモ.
public static Object invoke(final Object target, final String methodName, final Object... params) throws Exception {
List<Class<?>> parameterTypes = new ArrayList<Class<?>>();
for (Object o : params) {
parameterTypes.add(o.getClass());
}
Class<?> targetClass = target.getClass();
Method method = targetClass.getMethod(methodName, parameterTypes
.toArray((new Class<?>[] {})));
return method.invoke(target, params);
}
Popularity: 8% [?]
No comments yet.