I am experimenting around with JRuby – generating java from ruby files. I have an abstract class in ruby that implement a Java interface, and child classes extending this. also in ruby.
I’m running into the problem as described on http://jira.codehaus.org/browse/JRUBY-6342 where all the generated java files only extend RubyObject.
I am wondering if anyone else has encountered this and have a workaround? Right now I have used a java_implement interface in each child class as they do not extend the abstract class.
I have included the snippet from JRUBY-6342 describing the problem:
The Java code generated by jrubyc –java does not appear to support Ruby class inheritance. Given the following simple example:
class A
def my_class; self.class.name end
endclass B < A
endThe generated class in B.java inherits from RubyObject rather than A, rendering the B class completely broken in Java.
On a somewhat related note, module inclusion doesn’t seem to work either. A class with include M doesn’t get M’s methods in the generated Java code.
Am I missing something in my understanding of Ruby or JRuby?
This is still an issue indeed as the jruby compiler still produces RubyObject for the classes.
The only workaround that I know to this is to use the JRuby
ScriptEnginefrom Java to eval your JRuby code. For example, here is some JRuby code:This code can then be called from a Java class like this:
Here the object returned by
evalcan be casted intoJFrame, just as you would expect. See also this question for that problem.