[英]Implementing a Java interface on the JRuby generated .class/.java file
I'm trying to implement a Java interface in a JRuby class, like this: 我正在尝试在JRuby类中实现Java接口,如下所示:
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: net.jruby.test.Service
接口很简单:
package net.jruby.test;
public interface Service
{
int sum(int a, int b);
}
After that I generate the .java class file with: 之后我生成.java类文件:
jrubyc --java ruby_service.rb
jrubyc --java ruby_service.rb
But the generated .java file (and consequently the .class file) do not implement the interface, look: 但是生成的.java文件(以及因此的.class文件) 没有实现接口,看看:
public class RubyService extends RubyObject {
Is there any way to achieve this? 有没有办法实现这个目标?
Found the answer, instead of this: 找到答案,而不是这个:
include Service
I needed this: 我需要这个:
java_implements 'Service'
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.