【发布时间】:2016-03-14 16:16:04
【问题描述】:
有没有办法可以将fun1 的三个函数之一传递给fun3 作为eval 的参数,然后对其进行评估?代码:
public class Pruebas {
public static double fun1(double x){
return x*1;
}
public static double fun2(double x){
return x*2;
}
public static double fun3(double x){
return x*3;
}
public static double eval(funx,double x0){
/* funx at this point i expect it to be fun1, fun2 or fun3 */
double f=funx(x0);
return f;
}
}
【问题讨论】:
-
有几种方法。使用哪个取决于具体情况。你想达到什么目的?
-
根据您想要做什么,Strategy and Template Method design patterns 可能对此有用。
-
您好,感谢您的回复,我简化了问题,但我正在做的是一个热力学程序,它使用了很多数学,特别是数值方法,需要我多次评估很多函数每次使用不同的输入参数。
-
您在使用 Java 8 吗?还是更早的版本?