私はEJMLを使用しています。クラスLinearSolver_B64_to_D64
を使用します。このクラスには、LinearSolver<BlockMatrix64F>
というインタフェースを持つLinearSolver_B64_to_D64(LinearSolver<BlockMatrix64F> alg)
のコンストラクタがあり、クラスにはすでにLinearSolver
が実装されています。interface as parameterの使い方は?
私が知っているもの: 通常、特定のクラスでそのインターフェイスを実装するよりも、インターフェイスを作成します。 インターフェイスをパラメータとする(特定のクラスの)関数について読んでいます。これは、関数がクラスについて何かを知る必要がないためです。
私の質問: 私は、パラメータとしてインターフェイスを渡す方法を知らないので、私は、クラスLinearSolver_B64_to_D64
を初期化する方法がわかりません。
更新: 私は、次のコードを試してみました:
public class UseMatrixInterface{
public UseMatrixInterface(){
}
public void do1(){
DenseMatrix64F a = new DenseMatrix64F(3,3);
LinearSolver_B64_to_D64 ls = new LinearSolver_B64_to_D64(null);
//it throws a nullpointer exeption. I assume, it is because i used null
//instead of the requiered parameter.
ls.invert(a);
a.print();
}
public void do2(){
LinearSolver<BlockMatrix64F> lsD;
LinearSolver_B64_to_D64 ls = new LinearSolver_B64_to_D64(lsD);
//not working, because lsD cannot be initialised;
}
}
インターフェイスの実装を実際の値として渡す必要があります。 –
LinearSolverインターフェイスを実装するクラスのインスタンスが必要です。 –