![]() | *Really* extend Java class in JRuby |
|
07 Feb 2012, 15:00
Hans-Joerg von Mettenheim (1 post) |
For example when dealing with Eclipse rcp applications one may encounter the following Java code to implement a view:
When I use the Ruby translation
the compiled java class ends up extending RubyObject, like all(?!) compiled JRuby classes. The challenge here is that MyView will be instantiated and called by the rcp framework. And the framework expects a class that extends ViewPart (and not RubyObject). A simple though not elegant solution is to write a Java wrapper that will instantiate a Ruby class and delegate the relevant calls to this class. The Java wrapper is boilerplate code and could even be autogenerated. I’m wondering: how do other people translate the Thanks, |
|
07 Feb 2012, 20:58
Ian Dees (192 posts) |
Hello, Hans-Joerg. Inheriting from an arbitrary class is tough to do with the compiler; I’ll ask my co-authors to chime in here if they’re aware of a way. With the interpreter, though, there’s a happier story. With the following in
...and the following in
...then the following program is able to create instances of the derived Ruby object and cast them to the Java base class:
So perhaps it’s possible to create a minimal Java wrapper that does the construction using the above technique, but doesn’t require any forwarding for the actual methods. I’m not sure how feasible this is with RCP applications. Reports of using JRuby to build Eclipse (or at least SWT) apps are mixed. On the one hand, there’s the Glimmer library for SWT apps. On the other hand, there’s an RCP case study where the implementers kept the top-level GUI bits in Java, and used JRuby for the application logic. —Ian |
| You must be logged in to comment |

