简体   繁体   English

jruby-从符号设置Java对象

[英]jruby - setting java objects from a symbol

I have a java class I am using in my jruby project and in ruby I can set a value to an object via the send method. 我在jruby项目中使用了一个Java类,在ruby中,我可以通过send方法为对象设置一个值。 I am doing the same in jruby but using the java_send method instead. 我在jruby中做同样的事情,但是改用java_send方法。 However, when I try using this I get the following error TypeError: can't convert Java::JavaIo::File into Array from org/jruby/java/proxies/JavaProxy.java:321:in 'java_send' 但是,当我尝试使用它时,出现以下错误TypeError: can't convert Java::JavaIo::File into Array from org/jruby/java/proxies/JavaProxy.java:321:in 'java_send'

I have a java instance and I need to call the object via a symbol. 我有一个Java实例,需要通过符号调用对象。 Below is what I am doing in the code: 下面是我在代码中正在做的事情:

OUTPUT_FILES = [:make, :model]

javaArgs = javaArgs.new
OUTPUT_FILES.each do |filename|
   file = java.io.File.new(path, "#{filename.to_s.underscore}.csv")
   file.createNewFile
   javaArgs.java_send(filename, file)
end

and just to make sure when I do javaArgs.make = file it works without any problems. 并且只是为了确保当我执行javaArgs.make = file它可以正常工作。

java_send期望其参数作为数组传递: javaArgs.java_send filename, [ file ]

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM