Java <->Scala 集合转换,Scala 2.10 [英] Java <-> Scala Collection conversions, Scala 2.10
问题描述
查看 JavaConversions
和 JavaConverters
中的代码,我不确定哪种正确"方式(使用 2.10)在 Java 和 Scala 集合之间转换(在任一方向)) 是.
Looking at the code in JavaConversions
and JavaConverters
, I am unsure which the "correct" way (with 2.10) to convert between Java and Scala collections (in either direction) is.
似乎有很多@deprecated 注释.
There seem to be lots of @deprecated annotations.
Scala 团队(类型安全?)是否发布了明确的答案?
Has a definitive answer from the Scala Team (Typesafe?) been published?
谢谢,约翰
推荐答案
我不知道有任何此类声明,但您应该始终使用 JavaConverters
,即需要您指出的那些使用 .asScala
和 .asJava
进行转换.
I don't know of any such proclamation, but you should just always use JavaConverters
, i.e. the ones that require you to indicate conversions with .asScala
and .asJava
.
据我所知,JavaConverters
是在 2.8.1 中引入的,因为 2.8 中的 JavaConversions
很危险,并且很容易意外地转换你没有的东西期待.
As I understand it, JavaConverters
were brought in in 2.8.1 because the JavaConversions
in 2.8 were dangerous and made it easy to accidentally convert things where you weren't expecting it.
这篇关于Java <->Scala 集合转换,Scala 2.10的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!