public Object callJavaMethod(Object o, String method, Object[] args) {
try {
Method m = o.getClass().getMethod(method, new Class[] { Object[].class });
return m.invoke(o, args);
} catch (SecurityException e) {
return null;
} catch (NoSuchMethodException e) {
return null;
} catch (IllegalArgumentException e) {
return null;
} catch (IllegalAccessException e) {
return null;
} catch (InvocationTargetException e) {
return null;
}
}
Method m = null;
Method[] methods = o.getClass().getMethods();
for (int i=0; i < methods.length; i++) {
if ((methods[i].getName().equals(method)) && (methods[i].getParameterTypes().length == args.length)) {
m = methods[i];
}
}
if (m!=null) return m.invoke(o, args);
else return null;
Wildcard hat gesagt.:Das ist keine Lösung.
Wildcard hat gesagt.:Du musst das Class[] in einer Schleife aufbauen.