2

I need to pass a hashmap from a jruby function into a Java function. I have tried it this way with no luck.

def rubyfunction
    clazz = com.package.clazz
    params = java.util.HashMap.new({:ID => 1})       
    clazz.javafunction(params)
end


public class clazz{
    public void javafunction(HashMap<String, Object> params){
        params.get("ID") //Gives back null
    }
}

Is there a proper way to convert a jruby hashmap into a java hashmap?

2
  • What do you mean "no luck"? Is there an error? Commented Aug 20, 2013 at 19:42
  • When trying to grab the value with the key of "ID" it gives back null Commented Aug 20, 2013 at 19:45

1 Answer 1

1

After looking for a few hours I came across this link https://kenai.com/projects/jruby/pages/CallingJavaFromJRuby

From that I modified the code, which now works as intended

def rubyfunction
    clazz = com.package.clazz
    params = java.util.HashMap.new()
    value = 1.to_java Java::int
    params.put("ID", value)
    clazz.javafunction(params)
end
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.