5

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?

1
  • I've asked in the IRC channel and the mailing list with no (at least immediate) luck, so please don't point me there, I know those options Commented Mar 6, 2011 at 0:04

1 Answer 1

12

Found the answer, instead of this:

include Service

I needed this:

java_implements 'Service'
Sign up to request clarification or add additional context in comments.

2 Comments

Do you recall where you found this?
"Using JRuby" book, I think.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.