Search code examples
javajruby

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. I am doing the same in jruby but using the java_send method instead. 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'

I have a java instance and I need to call the object via a symbol. 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.


Solution

  • java_send expects its arguments passed as an array: javaArgs.java_send filename, [ file ]