您需要使用从 JRuby 1.4 开始可用的#java_send
或#java_alias
功能来选择您希望调用的方法。例子:
class Java::JavaUtil::Arrays
boolean_array_class = [false].to_java(:boolean).java_class
java_alias :boolean_equals, :equals, [boolean_array_class, boolean_array_class]
end
a1 = [false, true]
Java::JavaUtil::Arrays.boolean_equals a1, a1
# => TypeError: for method Arrays.equals expected [class [Z, class [Z]; got: [org.jruby.RubyArray,org.jruby.RubyArray]; error: argument type mismatch
Java::JavaUtil::Arrays.boolean_equals a1.to_java(:boolean), a1.to_java(:boolean)
# => true
a2 = [true, false]
Java::JavaUtil::Arrays.boolean_equals a1.to_java(:boolean), a2.to_java(:boolean)
# => false