JRuby Dilemma

Posted by Aaron Feng Mon, 16 Jul 2007 22:44:00 GMT

I submitted the following code to JRuby mailing list, and I haven't received any reponse yet. Can you spot the problem?

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;
    }
}

Here is my ruby code which calls the Java code above:

include Java
require 'my.jar'

class MyVector < 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 "found"
    else
      puts "not found"
      puts vec_from_java.java_class
    end

  end
end

r = MyRuby.new

The output from the ruby code :

not found

org.jruby.javasupport.proxy.gen.Vector$Proxy0

Comments

Leave a response

Comments