Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Implementing a Java interface on the JRuby generated .class/.java file

Tags:

java

jruby

I'm trying to implement a Java interface in a JRuby class, like this:

require 'java'
java_package 'net.jruby.test'
java_import "net.jruby.test.Service"

class RubyService
  include Service

  java_signature 'int sum(int, int)'
  def sum(a,b)
    a + b
  end
end

The net.jruby.test.Service interface is dead simple:

package net.jruby.test;

public interface Service
{
  int sum(int a, int b);
}

After that I generate the .java class file with:

jrubyc --java ruby_service.rb

But the generated .java file (and consequently the .class file) do not implement the interface, look:

public class RubyService extends RubyObject  {

Is there any way to achieve this?

like image 977
Pablo Fernandez Avatar asked Mar 06 '11 00:03

Pablo Fernandez


1 Answers

Found the answer, instead of this:

include Service

I needed this:

java_implements 'Service'
like image 132
Pablo Fernandez Avatar answered Nov 17 '22 13:11

Pablo Fernandez