I'm calling a Scala method, from Java. And I need to make the conversion from Seq to List.
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?
Using Scala 2.9.3
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);
}
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);
}