I am working in Java. I am calling a scala function which returns a Seq[String]. To convert it to java's List, I tried using scala.collection.JavaConverters's asJava. But this does not seem to work.
Answers on similar questions have suggested either using JavaConversions or WrapAsJava, both of which are deprecated.
Similar Question - Converting Scala seq<string> to Java List<string>
//someScalaFunc returns a Seq[String]
List<String> listA = someScalaFunc();
由于JavaConversions
已被弃用 ,你可以使用JavaConverters
此:
List<String> listA = scala.collection.JavaConverters.seqAsJavaList(someScalaFunc())
您可以通过导入以下代码来使用Java到Scala隐式转换器:
import scala.collection.JavaConversions._
import scala.collection.JavaConverters._
val scalaList = List("A", "B", "c")
scalaList.asJava
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.