假设我有一个 scala 库,它公开了采用 scala 特定类型的 api 方法(比如一个在 java 中不可用的集合)。
这是否意味着您必须更改公开的参数,或者将集合更改为 java 兼容类型,然后对其进行迭代并初始化特定于 Scala 的集合?
基本上我的意思是,在设计将在 java 中使用的 scala api 时,您必须使用兼容的类型,否则如果您必须迭代并将 java 集合映射到 scala,您将付出性能/内存损失一个对吗?
基本上就是这些选项吗?
最佳答案
来自 http://www.scala-lang.org/faq/4
What does it mean that Scala is compatible with Java?
The standard Scala backend is a Java VM. Scala classes are Java classes, and vice versa. You can call the methods of either language from methods in the other one. You can extend Java classes in Scala, and vice versa. The main limitation is that some Scala features do not have equivalents in Java, for example traits.
此外,要回答您的问题,请访问 How to use scala.collection.immutable.List in a Java code
关于java - Scala api 和 java 兼容性,你必须重新映射吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14078348/