A
A
Andrey Andryushchenko2015-05-09 13:40:37
Java
Andrey Andryushchenko, 2015-05-09 13:40:37

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

3 answer(s)
M
Max, 2015-05-09
@delphikettle

Can!

Class<?> c = Class.forName("class name");
Method  method = c.getDeclaredMethod ("method name", parameterTypes)
method.invoke (objectToInvokeOn, params)

R
Rikcon, 2015-05-09
@Rikcon

stackoverflow.com/questions/4138527/how-to-call-a-...

O
olexandr7, 2015-05-09
@olexandr7

Try this:
this.variableWithName

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question