Invoking a Java method from Ruby that takes a Java primitive double with a Ruby BigDecimal
I'm getting an error when attempting to call a method on a Java object from JRuby when the Java method's signature has a primitive double and the parameter I pass is a Ruby BigDecimal. Is there any implicit conversion that's possible there or does it have to be handled explicitly. I'm invoking the Java object's method with send if that makes any difference.
java_object.send :some_method, a_big_decimal
(This could actually invoke methods with different type signatures on the Java object so I don't only have to worry about BigDecimals here which is why I'd lik开发者_Go百科e to avoid explicitly handling it if possible)
I've also tried
java_object.send :some_method, a_big_decimal.to_java
But that produces a different error:
TypeError: cannot convert instance of class org.jruby.java.proxies.ConcreteJavaProxy to double
I was just Googling for a solution to a similar problem, when I came across this question (only 3 hours after you posted it ... damn Google is fast!).
I was eventually able to solve my problem by doing (the equivalent of) this:
java_object.some_method a_big_decimal.to_f
Hopefully that will work for you?
精彩评论