L
Lian Liming
I am working on a programme dynamically invoking a method from the
input. My program will receive a string including the class name and
the method name, For example, "classA.methodA". The parameters for the
method will also be passed into my programme. Then I should invoke the
method "methodA" in class "classA". The classA is written by others and
I don't know how it is implemented.
Now my problem comes.If the authors of the classes in which I will
invoke the methods use stand way of "ClassA a = new ClassA()" to
instantiate the class. It will be easy for me, since I can easily make
a new instance to complete the task. But some authors like to use
"factory method" to instantiate the class, it seems impossible for my
programme to know where are the "factory method". Factory methods can
be in any names without restriction.
So I wonder if there are some possible ways to complete my task? Thanks
for any suggestions!
PS: I am not working on Java very long and English is my second
language. So if there is anything unclear, please think free to point
it out. Thanks again.
input. My program will receive a string including the class name and
the method name, For example, "classA.methodA". The parameters for the
method will also be passed into my programme. Then I should invoke the
method "methodA" in class "classA". The classA is written by others and
I don't know how it is implemented.
Now my problem comes.If the authors of the classes in which I will
invoke the methods use stand way of "ClassA a = new ClassA()" to
instantiate the class. It will be easy for me, since I can easily make
a new instance to complete the task. But some authors like to use
"factory method" to instantiate the class, it seems impossible for my
programme to know where are the "factory method". Factory methods can
be in any names without restriction.
So I wonder if there are some possible ways to complete my task? Thanks
for any suggestions!
PS: I am not working on Java very long and English is my second
language. So if there is anything unclear, please think free to point
it out. Thanks again.