简体   繁体   English

JRuby和Java对象

[英]JRuby and Java objects

Please tell me if it is possible to do the following: 请告诉我是否可以执行以下操作:

  • create an instance of a specific class in Java 在Java中创建特定类的实例
  • pass it to JRuby to do something with it 把它传递给JRuby用它做点什么
  • continue using the "modified" version in Java 继续使用Java中的“修改”版本

May you provide a small working example? 你能提供一个小例子吗?

EDIT: It turns out that embedding was the simplest way to achieve this. 编辑:事实证明,嵌入是实现这一目标的最简单方法。 More information is available on Embedding JRuby . 有关嵌入JRuby的更多信息。

Yes it's possible. 是的,这是可能的。 This page on the JRuby wiki should get you started. JRuby wiki上的这个页面应该可以帮助您入门。

这是我使用的解决方案: 直接JRuby嵌入

It depends on what you mean by "do something". 这取决于你做什么意思“做某事”。 If you mean "redefine a method", then the answer is no, not really. 如果你的意思是“重新定义一种方法”,那么答案是否定的,不是真的。 The new method will be used by jruby, but any calls to the method in java will continue to invoke the old method. 新方法将由jruby使用,但是在java中对方法的任何调用都将继续调用旧方法。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM