JRuby: import vs include vs java_import vs include_class

不问归期 提交于 2019-11-30 12:34:04

问题


why so many different ways to include Java classes into JRuby? What are the differences? Which one should I use?


回答1:


You can find quite a few examples about working with Java classes at:
https://github.com/jruby/jruby/wiki/CallingJavaFromJRuby

It states, that you should use java_import instead of import due to the JRUBY-3171 bug.
Also include_class is or will be deprecated (JRUBY-3797) in favor of java_import.

Currently java_import is the recommended way to import a Java class.




回答2:


import doesn't play well with Rake, so it's discouraged. java_import is the newest, and recommended. include_class has been deprecated. Apart from that they all do the same thing, and are actually aliases of each other.

import is an alias for java_import and java_import calls include_class.



来源:https://stackoverflow.com/questions/2578582/jruby-import-vs-include-vs-java-import-vs-include-class

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