S
Serge
Hello,
I am wondering if I could use the Java reflection API to dynamically
modify the methods of a class. For example, I need a function that will
evaluate any f(x) at some x. Say I have something like:
static double eval_f(double val){
double result = (val)**2 + 2*(val) + 2;
return result;
}
The above eval_f() will evaluate f(x) = x^2 + 2x + 2 at any x. However, in
my program I need to be able to modify f(x) to whatever the user wants
(the user enters the function he wants and it is copied to a string; my
program simply finds roots of these functions using different numerical
methods). Thus, if the user wants f(x) = x^11 + 2 I want to be able to
dynamically modify the first line in the eval_f() function to:
double result = (val)**11 + 2;
It seems to me as if there might be a way to accomplish this using the
Reflection class although I am not a pro at using it. I would appreciate
if someone could tell me if it is indeed possible and how I can go about
doing this. Thanks so much.
Cheers,
Serge
I am wondering if I could use the Java reflection API to dynamically
modify the methods of a class. For example, I need a function that will
evaluate any f(x) at some x. Say I have something like:
static double eval_f(double val){
double result = (val)**2 + 2*(val) + 2;
return result;
}
The above eval_f() will evaluate f(x) = x^2 + 2x + 2 at any x. However, in
my program I need to be able to modify f(x) to whatever the user wants
(the user enters the function he wants and it is copied to a string; my
program simply finds roots of these functions using different numerical
methods). Thus, if the user wants f(x) = x^11 + 2 I want to be able to
dynamically modify the first line in the eval_f() function to:
double result = (val)**11 + 2;
It seems to me as if there might be a way to accomplish this using the
Reflection class although I am not a pro at using it. I would appreciate
if someone could tell me if it is indeed possible and how I can go about
doing this. Thanks so much.
Cheers,
Serge