【发布时间】:2015-05-28 14:57:35
【问题描述】:
我已经阅读了 Java 接口(回调),因为一位教授告诉我应该在我的一个程序中使用回调。在我的代码中,我可以从中“挑选”两个数学函数。当我想更改函数时,不要创建方法 activate() 并更改内部代码(从一个函数到另一个),他说我应该使用回调。但是,从我读到的关于回调的内容来看,我不确定这会有什么用。
编辑:添加我的代码
public interface
//the Interface
Activation {
double activate(Object anObject);
}
//one of the methods
public void sigmoid(double x)
{
1 / (1 + Math.exp(-x));
}
//other method
public void htan(final double[] x, final int start,
final int size) {
for (int i = start; i < start + size; i++) {
x[i] = Math.tanh(x[i]);
}
}
public double derivativeFunction(final double x) {
return (1.0 - x * x);
}
}
【问题讨论】:
-
能贴出你的相关代码吗?
-
该代码不应编译,因为您可能在接口中没有实现
-
对,我不是想编译上面的代码,而是展示一个我在做什么的例子
标签: java methods interface callback