[英]How can I call a Ruby method that takes a Hash from Java?
I've declared a Ruby method as: 我已将Ruby方法声明为:
require 'jruby/core_ext'
require 'java'
java_signature void test(java.util.HashMap)
def test(options={})
puts options[:name]
end
How can I call this method? 如何调用此方法? Please let me know if I need to modify java_signature. 请让我知道是否需要修改java_signature。
The easiest way is to implement an interface that your Java code expects, then pass an instance of that object to Java code. 最简单的方法是实现 Java代码期望的接口 ,然后将该对象的实例传递给Java代码。 This assumes that JRuby will be the "main" of your program. 假设JRuby将成为程序的“主”。 If you need Java to be the "main" but still want to call Ruby code, you will need to look at the JRuby Embed (previously Red Bridge) API . 如果您需要Java作为“主要”对象,但仍想调用Ruby代码,则需要查看JRuby Embed(以前称为Red Bridge)API 。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.