Hello List,
I want to write a JRuby class which implements a Java interface.
For example, in Java I might write this:
public class MyJavaClass implements MyJavaInterface {
// Java code goes here.
}
Google pointed me in this direction:
http://www.google.com/search?q=Can+a+JRuby+class+implement+an+interface
Then here:
http://kenai.com/projects/jruby/pages/CallingJavaFromJRuby#Interfaces
And I see this:
Implementing Java Interfaces in JRuby
JRuby classes can now implement more than one Java interface. Since
Java interfaces are mapped to modules in JRuby, you implement them not
by subclassing, but by mixing them in.
class SomeJRubyObject
include java.lang.Runnable
include java.lang.Comparable
end
So, I wrote this:
#!/usr/bin/env jruby
sjo.rb
require ‘java’
class SomeJRubyObject
include java.lang.Runnable
include java.lang.Comparable
end
I transformed it into a Java class:
jrubyc --javac some_jruby_object.rb
I inspected the resulting Java class:
import org.jruby.Ruby;
import org.jruby.RubyObject;
import org.jruby.javasupport.util.RuntimeHelpers;
import org.jruby.runtime.builtin.IRubyObject;
import org.jruby.javasupport.JavaUtil;
import org.jruby.RubyClass;
public class SomeJRubyObject extends RubyObject {
private static final Ruby ruby = Ruby.getGlobalRuntime();
private static final RubyClass metaclass;
Q1: I was expecting/hoping/wanting to see this:
public class SomeJRubyObject extends RubyObject implements Runnable,
Comparable {
Why is the class generated by jrubyc missing the “implements”
declaration?
Q2: How do I write JRuby syntax which would result in an “implements”
declaration appearing in my .java file should I choose to generate the
.java file with jrubyc?
The reason I want to do this is that I want to use an API written in
Java.
But I really want to avoid writing Java.
One thing this API expects me to do is write Java classes which
implement an interface in the API.
If I can write a class which implements this interface, then the API
can copy data into my objects via callback methods.
This will make me happy because I want that data.
To unsubscribe from this list, please visit:
http://xircles.codehaus.org/manage_email