我正在从 Java 调用 Scala 方法.我需要进行从 Seq 到 List 的转换.
I'm calling a Scala method, from Java. And I need to make the conversion from Seq to List.
我无法修改 Scala 方法的签名,因此无法使用 scala.collection.JavaConversions._
I can't modified the signature of the Scala method, so I can't used the asJavaCollection method from scala.collection.JavaConversions._
关于如何实现这一点的任何想法?
Any ideas of how can I achieve this?
使用 Scala 2.9.3
Using Scala 2.9.3
您使用 JavaConversions 走在正确的轨道上,但是此特定转换所需的方法是 seqAsJavaList代码>:
You're on the right track using JavaConversions, but the method you need for this particular conversion is seqAsJavaList:
java.util.List<String> convert(scala.collection.Seq<String> seq) {
return scala.collection.JavaConversions.seqAsJavaList(seq);
}
更新:JavaConversions 已弃用,但可以在 JavaConverters.
Update: JavaConversions is deprecated, but the same function can be found in JavaConverters.
java.util.List<String> convert(scala.collection.Seq<String> seq) {
return scala.collection.JavaConverters.seqAsJavaList(seq);
}
这篇关于从 scala.collection.Seq<String> 转换到 java.util.List<String>在 Java 代码中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!
“Char 不能被取消引用"错误quot;Char cannot be dereferencedquot; error(“Char 不能被取消引用错误)
Java Switch 语句 - 是“或"/“和"可能的?Java Switch Statement - Is quot;orquot;/quot;andquot; possible?(Java Switch 语句 - 是“或/“和可能的?)
Java替换字符串特定位置的字符?Java Replace Character At Specific Position Of String?(Java替换字符串特定位置的字符?)
具有 int 和 char 操作数的三元表达式的类型是什么What is the type of a ternary expression with int and char operands?(具有 int 和 char 操作数的三元表达式的类型是什么?)
读取文本文件并存储出现的每个字符Read a text file and store every single character occurrence(读取文本文件并存储出现的每个字符)
为什么我需要在 byte 和 short 上显式转换 char 原语Why do I need to explicitly cast char primitives on byte and short?(为什么我需要在 byte 和 short 上显式转换 char 原语?)