sige 1 year ago
parent
commit
baad1b96c4
  1. 2
      pom.xml
  2. 30
      src/main/java/com/iflytop/uf/util/UfClassHelper.java

2
pom.xml

@ -10,7 +10,7 @@
</parent>
<groupId>com.iflytop</groupId>
<artifactId>uf</artifactId>
<version>0.0.63</version>
<version>0.0.64</version>
<name>uf</name>
<description>uf</description>
<properties>

30
src/main/java/com/iflytop/uf/util/UfClassHelper.java

@ -40,25 +40,19 @@ public class UfClassHelper {
}
// invoke method
public static Object invokeMethod(Object obj, String methodName, List<Object> args) throws NoSuchMethodException {
try {
Class<?>[] parameterTypes = new Class<?>[args.size()];
for (int i = 0; i < args.size(); i++) {
parameterTypes[i] = args.get(i).getClass();
}
Method method = obj.getClass().getMethod(methodName, parameterTypes);
public static Object invokeMethod(Object obj, String methodName, List<Object> args) throws NoSuchMethodException, InvocationTargetException, IllegalAccessException {
Class<?>[] parameterTypes = new Class<?>[args.size()];
for (int i = 0; i < args.size(); i++) {
parameterTypes[i] = args.get(i).getClass();
}
Method method = obj.getClass().getMethod(methodName, parameterTypes);
if ( method.getReturnType().equals(Void.TYPE) ) {
method.invoke(obj, args.toArray());
return null;
} else {
return method.invoke(obj, args.toArray());
}
} catch (IllegalAccessException e) {
throw new RuntimeException(e);
} catch ( InvocationTargetException e ) {
throw new RuntimeException(e.getCause().getMessage());
}
if ( method.getReturnType().equals(Void.TYPE) ) {
method.invoke(obj, args.toArray());
return null;
} else {
return method.invoke(obj, args.toArray());
}
}
// get all classes in package

Loading…
Cancel
Save