Click to See Complete Forum and Search --> : Alternative to Function Pointers in Java


Savita
April 6th, 1999, 07:37 AM
We are working on a repository based system. We have stored function names in a database table.
These functions are nothing but class files.
Depending upon user selection, function name will be retrieved from the table. We need to execute this function (service),
but we are getting just a String which contains the function name. In C++ we can make use of Function pointers for the same.
Is there any means to do it in Java?

April 6th, 1999, 12:33 PM
I'll respond, even if it's not C++.

I'm not 100% conversant in Java, but I know it has a magic trick that C++ does
not have: it's called "reflection". You can create an instance of any class
given a string name. For example if you want to create an instance of the
class foo, you can create it if you have a string equal to "foo". Once the
instance is created, you can call any member. I'm not sure of the syntax, but
this is one thing that you cannot do in standard C++.

Overall, It's *easier* in Java than in C++ to do what you want.

Check out this link:
http://www.javasoft.com/docs/books/tutorial/reflect/index.html


Regards,

Paul McKenzie