Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

scala 2.8 implict java collections conversions

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]          
like image 869
nablik Avatar asked Jan 20 '26 10:01

nablik


1 Answers

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
like image 127
oxbow_lakes Avatar answered Jan 21 '26 22:01

oxbow_lakes



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!