|
Re: [jruby-user] JRuby array to Java array: msg#00191lang.jruby.user
This should work: tup = OtpErlangTuple.new( [firstErlObject, secondErlObject].to_java(OtpErlangObject) ) -Bill On Nov 21, 2007 11:46 AM, tsuraan <tsuraan@xxxxxxxxx> wrote: > My first two attempts got rejected, so hopefully this will get through... > > I'm using the Erlang JInterface library > (http://www.erlang.org/doc/apps/jinterface/index.html ) to communicate > between my ruby code and my erlang code. One of the key objects in this > library is the OtpErlangTuple, which takes an array of OtpErlangObject > instances as the argument to its constructor. Looking through the Jira bug > reports, I found that you can make a JRuby java array like so: > > ary = OtpErlangObject[2].new > > And then assignment is just like assignment to any other array, and the > tuple can be constructed with ary as its constructor argument. What I'm > wondering is why this can't be done in a more ruby-ish fashion. What I want > to be able to do is: > > tup = OtpErlangTuple.new [ firstErlObject, secondErlObject, etc ] > > but the JRuby array is not a Java array, so this gives a NameError. JRuby > arrays has a to_java method, which converts the org.jruby.RubyArray into a > java.lang.Object, but that's still not a valid array. I've also tried > > tup = OtpErlangTuple.new OtpErlangObject[2].new( [ firstErlObject, > secondErlObject ] ) > > but that that gives the puzzling message "NativeException: > java.lang.IllegalArgumentException: array element type mismatch." All the > elements in the JRuby array are OtpErlangObjects, so I don't know what the > type mismatch is. Is there a clean way to convert a JRuby array into a Java > one, or do I just have to make the array using the Object[size].new and > assign all the elements by hand? > > --------------------------------------------------------------------- To unsubscribe from this list please visit: http://xircles.codehaus.org/manage_email |
|
| <Prev in Thread] | Current Thread | [Next in Thread> |
|---|---|---|
| Previous by Date: | Re: [jruby-user] Running watir on jruby: 00191, Charles Oliver Nutter |
|---|---|
| Next by Date: | Re: [jruby-user] Unit test rollback and autocommit on sqlserver 2005: 00191, Nick Sieger |
| Previous by Thread: | [jruby-user] JRuby array to Java arrayi: 00191, tsuraan |
| Next by Thread: | Re: [jruby-user] JRuby array to Java array: 00191, tsuraan |
| Indexes: | [Date] [Thread] [Top] [All Lists] |
| News | FAQ | advertise |