Can I define a Java subclass in ruby, then instantiate it in Java?

孤者浪人 提交于 2019-12-05 19:01:33

I've come up with a workaround for now, but it's not pretty.

In brief: I can't return RubySub.become_java! (which is nil, because of JRUBY-6105) or try to return RubySub and convert from a RubyClass to a Class.

Instead, I return RubySub.method(:new), which shows up as a RubyMethod. I can call this, and it creates an IRubyObject which is actually an instance of the subclass. This can be cast to the Java superclass using JavaEmbedUtils.rubyToJava(). Like I said, it's not pretty but it works.

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!