我正在使用一个接受重写方法的类 我的意思是可选参数签名(不确定在这种情况下是否重要,但也许)
当我从IRB调用它时,它按预期工作,例如,它接受参数
(用[过滤]过滤命名空间和密码,以保密秘密,我的公司很开心)
jruby-1.5.0 > require 'java'
=> true
jruby-1.5.0 > Dir.glob('lib/java/*.jar').each{|jar| require jar}
=> ["lib/java/[filtered].jar", "lib/java/[filtered].jar", "lib/java/[filtered].jar"]
jruby-1.5.0 > import "[filtered].His351n1"
=> Java::[filtered]::His351n1
jruby-1.5.0 > broker = [filtered].Broker.new('[filtered]', '[filtered]')
=> #<Java::[filtered]::Broker:0x4c4936f3>
jruby-1.5.0 > rpc = "[filtered]"
=> "[filtered]"
jruby-1.5.0 > his = His351n1.new(broker, rpc)
=> #<Java::[filtered]::His351n1:0x7fb6a1c4>
这是我的规范和匹配代码
before(:each) do
@base = Legacy::Base.new
end
it "should create a valid his351n1 object" do
his = @base.create_his351n1
puts his.inpsect
end
# from within Legacy::Base
def create_his351n1
his = His351n1.new(build_broker, rpc)
end
最后,在对His351n1.new
的调用中失败的错误1)
ArgumentError in 'Legacy::Base should create a valid his351n1 object'
wrong # of arguments(2 for 0)
为了使问题复杂化,在irb上,这显然也是有效的:
jruby-1.5.0 > his = His351n1.new
=> #<Java::[filtered]::His351n1:0x5ad3c69c>
此外,这里是重写的java方法
public His351n1() {
super();
}
public His351n1(Broker broker) {
this(broker, DEFAULT_SERVER);
}
public His351n1(BrokerService bs) {
this(bs.getBroker(), bs.toString());
}
public His351n1(Broker broker, String serverAddr) {
super(broker, serverAddr, "string", true);
}
public His351n1(final Broker broker, final String serverAddr, final String library)
{
super(broker, serverAddr, library, true);
}
答案 0 :(得分:0)
似乎你必须在对象的实例化中要求整个命名空间:
his = Java::[filtered_namesapce]::His351n1.new(build_broker, rpc)