Per farlo sto pensando di usare il metodo valueOf(string_value) per fare il casting corretto dei parametri del metodo.
Nella maggioranza dei casi (Boolean, Integer, Double...)(Tipi primitivi) dovrebbe funzionare.
In pratica io prelevo i parametri-dati in formato testuale quindi dalla Stringa devo convertirli nel Type corretto per poi invocare tramite il method.invoke(class, parameter[]) il metodo.
Per il momento questo è il codice, ma non funziona, consigli?
Codice: Seleziona tutto
Method[] class_methods = frame.getClass().getMethods();
for(Method cls_method : class_methods) {
String method_name = cls_method.getName();
for(String str_method_name : this.methods.keySet()) {
if (str_method_name.equals(method_name)) {
if (this.methods.get(method_name)!=null) {
ArrayList<Object> method_values = this.methods.get(method_name);
//new cls_method.getGenericParameterTypes()[0].getTypeName()("");
Parameter[] parameters = cls_method.getParameters();
Object[] objParameters = new Object[parameters.length];
int index = 0;
for(Parameter par : parameters) {
System.out.println(par.getType());
Class<?> myClass;
String sType = par.getType().getName();
sType = sType.substring(0,1).toUpperCase()+sType.substring(1,sType.length());
System.out.println(sType);
index++;
}
try {
cls_method.invoke(frame, objParameters);
} catch (IllegalAccessException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (InvocationTargetException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
}
