How should I properly invoke methods through an object of an class using reflection? The only thing I know about the classes the program should work with is that their constructor takes no parameters and all methods(which does not take any parameters as well) in the classes are supposed to return true if successful and false otherwise. But this invoke wont work, any tips?
String className = "Classname read from stdin";
Class testClass;
Object classObject;
Method[] methods;
testClass = Class.forName(className);
classObject = testClass.newInstance();
methods = testClass.getDeclaredMethods();
for (Method method : methods) {
boolean result;
result = (boolean) method.invoke(classObject);
System.out.println(result);
}
The exception I keep getting is "InvocationTargetException"
Aucun commentaire:
Enregistrer un commentaire