following question in stackoverflow addresses this question very well.
http://stackoverflow.com/questions/7166328/when-why-to-call-system-out-flush-in-java
http://stackoverflow.com/questions/7166328/when-why-to-call-system-out-flush-in-java
Method m =SimpleClass.class.getDeclaredMethod("simpleMethod", Integer.TYPE); m.setAccessible(true); //if security settings allow this Object o = m.invoke(null, 20); //use null if the method is static
Object obj;//object class which the method has
String methodName = "getName" //string that you need to invoke the method.
THEN GET THE METHOD LIKE THIS
java.lang.reflect.Method method;
try {
method = obj.getClass().getMethod(methodName, param1.class, param2.class, ..);
} catch (SecurityException e) {
// ...
} catch (NoSuchMethodException e) {
// ...
}
AFTER THAT YOU CAN INOKE IT LIKE THIS
try {
method.invoke(obj, arg1, arg2,...);
} catch (IllegalArgumentException e) {
} catch (IllegalAccessException e) {
} catch (InvocationTargetException e) {
}