Answer the question
In order to leave comments, you need to log in
Is it possible to call a method by its name?
Is it possible in Java to call a method by its name or by some key? The situation is this. I am reading a method name from a file (as well as the parameters to pass those to the method) and I need to call it. The question is, can this be done, and if so, how?
Answer the question
In order to leave comments, you need to log in
Can!
Class<?> c = Class.forName("class name");
Method method = c.getDeclaredMethod ("method name", parameterTypes)
method.invoke (objectToInvokeOn, params)
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question