我有一個實現接口方法的方法。它看起來像這樣:如何在方法中使用類類型泛型
@Override
public Double calculate(Class<Float> score) {
if (score == null) {
return null;
}
Double beta0 = new Double(-7.7631);
Double beta1 = new Double(0.0737);
Double beta2 = new Double(0.9971);
Log log = new Log();
Exp exp = new Exp();
Double logit = beta0 + (beta1 * score) + (beta2 * log.value(new Double(score + 1)));
Double rod = exp.value(logit)/(1 + exp.value(logit));
return rod;
}
接口
public interface Calculator<T,S> {
public T calculate(Class<S> params);
}
我得到一個編譯錯誤the operator '*' is not defined for the argument type(s) Double, Class<Float>
。
我想我預計這個,但不知道如何解決它。道歉,如果這是一個簡單的問題.....
你也許應該在'Class >' –
上閱讀一下。你也不清楚爲什麼你要使用類。你的代碼沒有使用'Double'而不是'double'的優點,並且使用'new Double(...)'將它帶到最大值。 – Holger
我試圖使用泛型,以便計算器的某些實現可以採用其他類型 – skyman