views:

352

answers:

1

I have 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 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]          
+8  A: 

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

From the 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
oxbow_lakes
Deja-vu all over again...
Daniel