how can i call a function whose name will be known only at run time
how can i make a call to a function whose name will be known only at run time
how can i make a call to a function whose name will be known only at run time
Just don't, if you have any pride.
Otherwise, look at the Reflection API, starting with the Class class.
By the way, Java doesn't have functions.
That's right, you problably should just not do that unless you have a very good reason for it.
Instead, have a function - we should say method - with a known name, taking a string as argument.
> By the way, Java doesn't have functions.
What is it with this pet peeve.
A function is a procedure that returns a value, Java has lots of those.
The fact that traditionally functions are called methods (something to do with Smalltalk I think) doesn't make them not-functions.
> What is it with this pet peeve.
Terminology.The JLS only defines methods, the usage of the term "functions" might lead to questions like "what's the difference between functions and methods in Java"... see "we all know that Objects are passed by reference".
> Instead, have a function - we should say method -
> with a known name, taking a string as argument.
Or, specified classes with known names and a no-arg c'tor that implement a mutual interface, so you can grab an instance using forName/newInstance, cast the reference and invoke the interface's doMagic() method.
As far as I know, "method" is the generic term of "function" (methods with return types) and "operation" (methods with no return type/ return type void).
-Puce
> > Instead, have a function - we should say method -
> > with a known name, taking a string as argument.
>
> Or, specified classes with known names and a no-arg
> c'tor that implement a mutual interface, so you can
> grab an instance using forName/newInstance, cast the
> reference and invoke the interface's doMagic() method.
@OP: Best you describe your actual problem, then we could help you with a better solution maybe.
-Puce