私は、さまざまな数の引数を取る、1つのメソッドを使用して数学演算のインターフェースを作成しました。
public interface MathOperation {
public <T extends Number> T calculate(T... args);
}
このクラスの単純な実装もありますが、これは機能しません。
private class Sum implements MathOperation {
@Override
public <T extends Number> T calculate(T... args) {
return args[0] + args[1];
}
}
問題は:
bad operand types for binary operator '+'
first type: T
second type: T
where T is a type-variable:
T extends Number declared in method <T>calculate(T...)
私が達成しようとしているのは、たとえば 2 つの Double を取り、Double を返す単純なクラスです。
これを達成する可能性はありますか?