<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet href="/stylesheets/rss.css" type="text/css"?>
<rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:trackback="http://madskills.com/public/xml/rss/module/trackback/">
  <channel>
    <title>Aaron Feng: JRuby Dilemma</title>
    <link>http://www.aaronfeng.com/articles/2007/07/16/jruby-dilemma</link>
    <language>en-us</language>
    <ttl>40</ttl>
    <description>Adventures in software development</description>
    <item>
      <title>JRuby Dilemma</title>
      <description>&lt;p&gt;I submitted the following code to JRuby mailing list, and I haven't received any reponse yet.  Can you spot the problem?&lt;/p&gt;

&lt;div class="typocode"&gt;&lt;pre&gt;&lt;code class="typocode_default "&gt;package my;
import java.util.Vector;

public class MyClassInJava {
    Vector vector;

    public MyClassInJava(java.util.Vector vector) {
        this.vector = vector;
    }

    public Object getVector() {
        return vector;
    }
}&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;

&lt;p&gt;Here is my ruby code which calls the Java code above:&lt;/p&gt;

&lt;div class="typocode"&gt;&lt;pre&gt;&lt;code class="typocode_default "&gt;include Java
require 'my.jar'

class MyVector &amp;lt; java.util.Vector
  def my_method
  end
end

class MyRuby
  def initialize
    my_vec = MyVector.new
    c = Java::my.MyClassInJava.new(my_vec)
    vec_from_java = c.getVector()

    if vec_from_java.respond_to?(:my_method)
      puts &amp;quot;found&amp;quot;
    else
      puts &amp;quot;not found&amp;quot;
      puts vec_from_java.java_class
    end

  end
end

r = MyRuby.new&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;

&lt;p&gt;The output from the ruby code :&lt;/p&gt;

&lt;p&gt;not found&lt;/p&gt;

&lt;p&gt;org.jruby.javasupport.proxy.gen.Vector$Proxy0&lt;/p&gt;</description>
      <pubDate>Mon, 16 Jul 2007 18:44:00 -0400</pubDate>
      <guid isPermaLink="false">urn:uuid:39ea1566-4e80-4813-89d7-f7af150c1e64</guid>
      <author>Aaron Feng</author>
      <link>http://www.aaronfeng.com/articles/2007/07/16/jruby-dilemma</link>
      <category>programming</category>
    </item>
  </channel>
</rss>
