I am attempting to use reflection Method.invoke() to execute a method based on user inputted text that specifies the Class, Method and parameters to execute. Something like this:
public Object invokeInput(String className, String methodName, List<Object> list) {
try {
Class<?> cls = Class.forName(className);
Method method = cls.getMethod(methodName, list.get(0).getClass());
return method.invoke(null, list.get(0));
} catch (Exception e) {
System.out.println(e);
}
return false;
}
Everything works as intended for the first execution of the method, but then the results of the first invoke() seem to be saved/cached and returned for all subsequent calls to the same method when supplied method parameter Object (first Object in "list") has the same reference, even though the internal fields of that parameter Object have changed and should result in a different method return.
Anyway to avoid this? or clear the cache somehow?
Any help is greatly appreciated.
Aucun commentaire:
Enregistrer un commentaire