Skip to content

Instantly share code, notes, and snippets.

@icshih
Created November 20, 2014 10:07
Show Gist options
  • Save icshih/d532e02a0233910715eb to your computer and use it in GitHub Desktop.
Save icshih/d532e02a0233910715eb to your computer and use it in GitHub Desktop.
invoke a method with parameter(s)
Class[] argTypes = new Class[1];
argTypes[0] = Object[].class;
Object[] argObj = new Object[1];
argObj[0] = objs;
Method n = null;
try {
n = g.getDeclaredMethod("processData", argTypes);
} catch (NoSuchMethodException | SecurityException e1) {
e1.printStackTrace();
}
try {
n.invoke(g.newInstance(), argObj);
} catch (IllegalAccessException | IllegalArgumentException
| InvocationTargetException | InstantiationException e1) {
e1.printStackTrace();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment