Scala 2.8 Import java conversions

I have a problem with JavaConversions with 2.8 beta:

import scala.collection.JavaConversions._
class Utils(dbFile : File, sep: String) extends IUtils {
    (...)
    def getFeatures() : java.util.List[String] =  csv.attributes.toList
}

And then the exception:

[INFO]  Utils.scala:20: error: type mismatch;
[INFO]  found   : List[String]
[INFO]  required: java.util.List[String]
[INFO]   def getFeatures() : java.util.List[String] =  csv.attributes.toList
[INFO]          
+3
source share
1 answer

JavaConversionsdoes not support conversion between scala List(immutable, recursive data structure) and java List(mutable sequence). An analog in scala is the buffer:

From scaladoc

The following conversions are
   supported : scala.collection.mutable.Buffer <=> java.util.List

You might want to change your code to:

def getFeatures() : java.util.List[String] 
    = new ListBuffer[String] ++ csv.attributes.toList
+8
source

Source: https://habr.com/ru/post/1736790/


All Articles