I am performing some tests using Berkeley DB Java edition. To store
data on this DB the data needs to be converted into Binary Arrays. To
perform this conversion without problems the Berkeley DB API offers
some Java classes that performs the task. One of this classes
determines what’s the best possible conversion depending on the
original data type.
Here you have an example on how the code would looks like in Java:
On Fri, Sep 26, 2008 at 6:59 AM, Guillermo A. [email protected] wrote:
I am getting the following error:
Others/TestJE.rb:35: for method getPrimitiveBinding expected
[java.lang.Class]; got: [org.jruby.RubyClass]; error: argument type mismatch
(TypeError)
Does anybody know how to pass the correct class as an argument?
This is a little ugly right now, we probably could be better about
intuiting what you want to do and coerce to the right class, but for
now you need to use #java_class instead of #class. Also, be careful
here that you’re not referring to the Ruby Time class – you may want
to make sure you use java.util.Date.java_class instead.
thanks for your answer. This worked out correctly in the example I am
testing.
I am just playing with Berkeley DB to learn about it before starting
the actual development.
Now I am trying something a little more complex and I am getting the
same error. The only one difference is that I am creating my own
class. In pure Ruby I’d write MyClass.class, but I am getting the same
error. If I write java_class instead I receive undefined method
`java_class’ for Sentences:Class (NoMethodError)
MyClass extends “Object” which defines the method class. Should I
extend also another class to get the method?
On Fri, Sep 26, 2008 at 10:06 AM, Guillermo A. [email protected] wrote:
MyClass extends “Object” which defines the method class. Should I extend
also another class to get the method?
Thanks,
GA
If it’s a pure Ruby class it won’t have that method. You can make it
more exposable to Java by including a java interface. The class still
won’t have a #java_class method, but instances will have #java_object
methods which will have a #java_class method:
class MyClass
include java.lang.Runnable
end
MyClass.new.java_object.java_class
=> InterfaceImpl437531645
Cheers,
/Nick
To unsubscribe from this list, please visit:
http://xircles.codehaus.org/manage_email
This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.