You cannot do this, this is not how reflection works.
You need to split your String
by .
and then loop and invoke methods in turn.
This ought to work
private static Object invokeMethods(final String methodString, final Object root) throws Exception {
final String[] methods = methodString.split("\\.");
Object result = root;
for (final String method : methods) {
result = result.getClass().getMethod(method).invoke(result);
}
return result;
}
A quick test:
public static void main(String[] args) throws Exception {
final Calendar cal = Calendar.getInstance();
System.out.println(cal.getTimeZone().getDisplayName());
System.out.println(invokeMethods("getTimeZone.getDisplayName", cal));
}
Output:
Greenwich Mean Time
Greenwich Mean Time