Please look at this piece of code:
testFunction(input, a, b, 100, new FPFunction() {
public double eval(double n) {
double whatShouldBeReturned = 2+n;
return whatShouldBeReturned;
}
}
);
Just to let you know FPFunction is an interface and it's code is:
interface FPFunction {
double eval(double n);
}
the code above helps me to do some calculation on "2+x" funtion and that's it. if I wanted to change my function I should hardcode that into my program code for example to use it for "x*5+3" function I should change implementation of FPFunction to this:
testFunction(input, a, b, 100, new FPFunction() {
public double eval(double n) {
double whatShouldBeReturned = n*5+3;
return whatShouldBeReturned;
}
}
);
and that is exactly what I don't like.I'd like to change the function via the user interface and not hardcode that. My assumption is that there is a way like this:
testFunction(input, a, b, 100, new FPFunction() {
public double eval(double n) {
String mytring="2+n";
double whatShouldBeReturned =AppropriateMethod(myString);
return whatShouldBeReturned;
}
}
);
- If you think this way is valid please tell me what could be "appropriateMethod(String s)"s body.
- or if you have any other idea to do this please say.
by the way if you think the topic's name is not good please edit it to something you want.