我不知道如何用 JRuby 中的 JAVA 类初始化接口对象。
在下面的代码中,OAuthService 是接口,ServiceBuilder 是类
爪哇 ::
OAuthService service = new ServiceBuilder()
System.out.println(">>>>>>>" + service.getClass());
Output >> class org.scribe.oauth.OAuth20ServiceImpl
但是在 JRuby 中我不知道在哪里编写 OAuthService 接口来初始化对象。
JRuby ::
service = ServiceBuilder.new()
puts service.java_class
Output >> class org.scribe.builder.ServiceBuilder
当我在 JAVA 中执行时,以下代码可以完美运行
OAuthService service = ServiceBuilder.new()
.provider(FacebookApi.class)
.apiKey(apiKey)
.apiSecret(apiSecret)
.callback("http://localhost:3000/oauth_callback/")
.build()
但是在Ruby中它给出了错误
错误 ::
irb(main):015:0> service = ServiceBuilder.new()
.provider(FacebookApi.class)
.apiKey(apiKey)
.apiSecret(apiSecret)
.callback("http://localhost:3000/oauth_callback/")
.build()
NoMethodError: undefined method `createService' for Class:Class
from org/jruby/gen/InterfaceImpl1679303904.gen:13:in `createService'
from (irb):15:in `evaluate'
from org/jruby/RubyKernel.java:1066:in `eval'
from org/jruby/RubyKernel.java:1409:in `loop'
from org/jruby/RubyKernel.java:1174:in `catch'
from org/jruby/RubyKernel.java:1174:in `catch'
from /home/krunal/.rvm/gems/jruby-1.7.3@integration_hub/gems/railties-3.2.13/lib/rails/commands/console.rb:47:in `start'
from /home/krunal/.rvm/gems/jruby-1.7.3@integration_hub/gems/railties-3.2.13/lib/rails/commands/console.rb:8:in `start'
from /home/krunal/.rvm/gems/jruby-1.7.3@integration_hub/gems/railties-3.2.13/lib/rails/commands.rb:41:in `(root)'
from org/jruby/RubyKernel.java:1027:in `require'
from script/rails:6:in `(root)'
irb(main):016:0>