If you just want to call another static method in the class, you can use the approach already identified by others:
Method method = Dialogs.getMethod(s, Integer.class); method.invoke(null, i);
But if you want to use a static method to call a non-static method, you will need to pass the object you want to reference or make selectDialog non-static.
function chooseDialog(Object o, String s, Integer i) { Method method = Dialogs.getMethod(o, Integer.class); method.invoke(o, i); }
But I do not think that this is the right OOP way to deal with this problem. And based on your comments, reflection is not absolutely necessary and Dialog chose to analyze the string and pass that the appropriate method is a much more typical approach. In any case, your unit tests should look the same.
if (s.equals("dialog1")) { dialog1(i); }
David
source share