1

ModelWeightsGuice Dependency Injectionを使用するオブジェクトを作成する必要があります。double[][]実行時に Guice 依存性注入を使用して配列をバインドするにはどうすればよいですか?

public class MW {

    private double[][] weights;
    private LogConditionalObjectiveFunction objectiveFunction;

    @Inject
    public MW(double[][] weights, LogConditionalObjectiveFunction func)
    {
        this.weights = weights;
        this.objectiveFunction = func;
    }

    public double[][] getWeights()
    {
        return this.weights;
    }

    public LogConditionalObjectiveFunction getObjectiveFunction()
    {
        return this.objectiveFunction;
    }
}

いくつかのアプローチを試しているときにこれを得ました:

1) No implementation for double[][] was bound.
  while locating double[][]
    for parameter 0 at com.data.MW.<init>(MW.java:13)
  while locating com.data.MW
    for parameter 0 at com.predictor.impl.MEP.<init>(MEP.java:50)
  at     com.ServletDependencyInjector$1.configureServlets(ServletDependencyInjector.java:72)
4

1 に答える 1

1

Guice 定数バインディングを使用する

@Inject
public ModelWeights(@Named("MyMatrix") double[][] weights, LogConditionalObjectiveFunction func) {
        this.weights = weights;
        this.objectiveFunction = func;
}

そして、あなたのGuiceセットアップコードで

@Override
protected void configure() {
   bind(double[][].class).annotatedWith(Names.named("MyMatrix")).toInstance(MY_MATRIX); 
}
于 2014-12-07T14:45:10.263 に答える