“棘手"从Java调用Scala代码? [英] "Trickiness" to calling Scala code from Java?

查看:230
本文介绍了“棘手"从Java调用Scala代码?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我真的想在我的Java应用程序中使用一个Scala库(仅以Scala编写).我正在尝试评估我是否可以做到这一点,而不会遭受任何隐藏的棘手动物/洞穴/陷阱的困扰.因此,我直接进入Scala常见问题解答,其中他们回答了这个问题 (好吧):

There is a Scala library (that only exists written in Scala) that I really want to use in my Java app. I am trying to evaluate whether I can do this or not without suffering any hidden gotchyas/caveats/pitfalls. So I went straight to the Scala FAQ, where they answer this very question (well, sort of):

从Scala代码访问Java类完全没有问题. 在Java中使用Scala类可能会比较棘手,特别是如果您的Scala类使用了泛型,多态方法或抽象类型等高级功能.

然后,我找到了其他几个站点(例如这一个站点),这似乎表明从Java内部调用Scala没问题,因为它都是已编译的JVM字节码.

I then found several other sites (such as this one) that seem to indicate there is no problem in calling Scala from inside Java, as it is all compiled JVM bytecode.

因此,我有两个非常矛盾的信息来源,我陷入了中间,试图确定哪些用例使从Java" tricky "调用Scala,而哪些用例是直截了当的.有什么想法吗?

So I have two very conflicting sources of information, and I'm stuck in the middle trying to determine what use cases make calling Scala from Java "tricky", and which use cases are straight forward. Any ideas?

推荐答案

如果您正在调用的scala库使用了棘手的"功能,那么我想您可以将其包装在scala中,以使包装器不会暴露任何调用代码的棘手"功能.

If the scala library you are calling uses "tricky" features, I suppose you could wrap it (in scala) in a manner such that the wrapper does not expose any of the "tricky" features to calling code.

这篇关于“棘手"从Java调用Scala代码?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆