I'd like to define a superclass in Java, then define a subclass in Ruby, then make instances of that subclass in Java. A little something like this:
// Java superclass
package myPkg;
public class Sup{
public Sup(){}
public abstract void foo(String a);
}
--
# Ruby code
include Java
require 'jruby/core_ext'
include_class 'myPkg.Sup'
class RubySub < Java::myPkg.Sup
def foo( a )
puts a;
end
end
RubySub.become_java!
RubySub
--
// Back in Java land
Ruby runtime = Ruby.newInstance();
IRubyObect ro = runtime.evalScriptlet(theRubyCodeAbove);
Class<Sup> clz = (Class<Sup>) JavaEmbedUtils.rubyToJava(runtime, ro, Class.class);
clz.newInstance().foo("Hey!");
I've tried the above code, but I get an InstantiationException from the newInstance() call. I want to have the class declared in Ruby at runtime, so e.g. running jrubyc to compile the Ruby code to a Java class definition ahead of time is out. What am I doing wrong here?
I've run through the bottom code segment in the debugger, and I'm definitely getting a RubyClass object returned from the evalScriptlet() call. Maybe there's an extra step involved to turn a RubyClass into a Class?
UPDATE: I have a lead -- apparently become_java! doesn't work if the class is a subclass of a Java class. Is there another way I can do this, or am I just boned?