[英]Why am I getting a NoMethodError calling this jRuby implementation of a java interface from a java class?
我遵循了类似问题的建议(链接: 如何从JRuby获得Java接口的正确类型的ruby实现? ),但这根本没有改变症状。
Java运行时异常:
org.jruby.exceptions.RaiseException: (NoMethodError) undefined method `doWork' for main:Object
Java执行代码:
Object worker= engine.get("worker");
MyInterface interfacedWorker = ((Invocable) engine).getInterface(worker,
MyInterface.class);
interfacedWorker.doWork(1,2);
java接口:
public interface MyInterface
{
public void doWork (int a, int b)
}
jRuby类:
class Worker_31415_2
java_implements 'com.myApp.MyInterface'
def doWork(a, b)
p a, b
end
end
worker=Worker_31415_2.new
你应该使用这个表格: -
require 'java'
require_relative 'classes'
class Worker
include com.myApp.MyInterface
java_signature 'doWork(int a, int b)'
def doWork(a, b)
p a, b
end
end
Worker.new.doWork(1, 2)
根据您的示例,用于已编译Java接口的Classes.jar对我有用!
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.