简体   繁体   English

如何调用从Java提取哈希值的Ruby方法?

[英]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.

相关问题 如何调用从 Kotlin 获取非空无效参数的 Java 方法? - How do I call a Java method that takes a Non-null Void parameter from Kotlin? 我如何在ruby中调用Java类 - how can i call a java class in ruby 如何调用采用 ServerHttpResponse 类型参数的方法? - How can I call a method which takes a parameter of type ServerHttpResponse? 如何从Java调用Flex / Flash / Actionscript方法? - How can I call a Flex/Flash/Actionscript method from Java? 如何从 Java 反射性地调用 Scala object 上的方法? - How can I reflectively call a method on a Scala object from Java? 如何检测 Java 中的方法调用? - How can I detect a method call in Java? 如何从javascript调用java方法? - How can a call a java method from javascript? 如何将数字从空手道传递给 Java? 如何调用带有数字的 Java 构造函数? - How do I pass numbers to Java from karate? How do I call a Java constructor that takes a number? 如何从C ++ / JNI调用Java方法,该方法采用Android Context参数 - How to call a Java method from C++ / JNI which takes an Android Context parameter 您将如何从 JNI 的本机端调用将 lambda 作为参数的 Java 方法? - How would you call a Java method that takes a lambda as an argument from the native side of JNI?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM