0

我正在尝试从 jRuby 的 JaCop 约束编程库中初始化此类。我使用了正确类型的参数,但由于某种原因,我不断收到此错误消息:

  NameError: no constructor for arguments
    (
      org.jruby.RubyArray,
      org.jruby.RubyArray,
      org.jruby.RubyArray,
      JaCoP.core.IntVar,
      JaCoP.core.IntVar)
    on Java::JaCoPConstraintsKnapsack::Knapsack
    (root) at rb/knapsack.rb:24

它指向的代码是这样的:

k = Jacop::Knapsack.new(@values, @weights, quantity, knapsackCapacity, knapsackProfit)

Java 类构造函数的签名是这样的:

public Knapsack(int[] profits,
                int[] weights,
                IntVar[] quantity,
                IntVar knapsackCapacity,
                IntVar knapsackProfit)

我不明白为什么 jRuby 抱怨找不到构造函数,因为它应该能够找到它。

4

1 回答 1

3

JRuby can not always guess "complicated" method args for you, you might want to try :

Jacop::Knapsack.new(@values, @weights, quantity.to_java(JaCoP.core.IntVar), knapsackCapacity, knapsackProfit)

or even helping with the int[] cast (should not be necessary) :

Jacop::Knapsack.new(@values.to_java(:int), @weights.to_java(:int), quantity.to_java(JaCoP.core.IntVar), knapsackCapacity, knapsackProfit)

于 2013-07-15T07:11:30.347 回答