Forum: JRuby Implementing a java interface with jruby

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
4e78065963ce042cbab1d735ee480be0?d=identicon&s=25 Josh Hester (Guest)
on 2013-10-17 16:17
(Received via mailing list)
Hi,

I'm trying to implement a very simple java interface in ruby.

On the java side I have:

package com.stuff;

public interface IProgressLiason {
 void voidMethod();
}

On the ruby side I have:

class ProgressLiason
  include com.stuff.IProgressLiason

  def voidMethod
    puts "foo"
  end

end

Then I pass that implementation into a java method expecting an
IProgressLiason object, and get the following error:

expected [class com.stuff.IProgressLiason]; got:
[ProgressLiason_1368958158]; error: argument type mismatch

Can anyone see anything I may have missed?  It's as if ruby isn't
recognizing that this class is implementing an interface.

Thanks!
8ec3fe4f1729b3c07e3ea19421e6b646?d=identicon&s=25 Benjamin Ortega (Guest)
on 2013-10-17 17:36
(Received via mailing list)
I would do this using java_implements and java_signature in JRuby 1.7.4:

class ProgressLiason
  java_implements 'com.stuff.IProgressLiason'

  java_signature 'void voidMethod()'
  def voidMethod
    puts "foo"
  end
end
This topic is locked and can not be replied to.