简体   繁体   English

从Java调用Scala代码的“技巧性”?

[英]“Trickiness” to calling Scala code from Java?

There is a Scala library (that only exists written in Scala) that I really want to use in my Java app. 我确实想在我的Java应用程序中使用一个Scala库(仅以Scala编写)。 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 FAQ, 他们回答了这个问题 (嗯,有点):

Accessing Java classes from Scala code is no problem at all. 从Scala代码访问Java类完全没有问题。 Using a Scala class from Java can get tricky, in particular if your Scala class uses advanced features like generics, polymorphic methods, or abstract types. 使用Java中的Scala类可能会很棘手,特别是如果您的Scala类使用了泛型,多态方法或抽象类型等高级功能时,尤其如此。

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. 然后,我发现了其他几个站点(例如this站点),似乎表明从Java内部调用Scala没问题,因为它都是已编译的JVM字节码。

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. 因此,我有两个非常矛盾的信息源,我被困在中间,试图确定哪些用例使从Java调用Scala 变得棘手 ”,哪些用例是直截了当的。 Any ideas? 有任何想法吗?

如果您要调用的scala库使用了“棘手的”功能,我想您可以将其包装在scala中,这样包装程序就不会向调用代码公开任何“棘手的”功能。

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

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