我已經閱讀了Java接口(回調),因爲我被教授告知我應該在我的程序中使用回調。在我的代碼中,我可以從中選擇兩個數學函數。當我想要改變函數時,我沒有做一個方法activate()和改變裏面的代碼(從一個函數到另一個函數),他說我應該使用回調函數。不過,從我讀過的關於回調的內容中,我不確定這將會如何。Java接口/回調使用2個可能的方法之一
編輯:加入我的代碼
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);
}
}
你可以發表你的相關的代碼? –
增加了一些代碼。 –
該代碼不應該編譯,因爲你可能沒有在接口實現 – danielspaniol