I need to implement a method that return a "Seq", in Java
But I encounter an error, I don't know how to solve it.
java.util.ArrayList cannot be cast to scala.collection.Seq
Here is my code so far
@Override
public Seq columnNames() {
List a = new ArrayList();
a.add("john");
a.add("mary");
Seq b = (scala.collection.Seq) a;
return b;
}
scala.collection.JavaConverters. doesn't seem to offer the possibility to convert as a Seq.
Thank you
解决方案
JavaConverters is what I needed to solve this.
import scala.collection.JavaConverters;
public Seq convertListToSeq(List inputList) {
return JavaConverters.asScalaIteratorConverter(inputList.iterator()).asScala().toSeq();
}