我有一个scala.collection.Set scalaSet : Set[Long].
我如何能够将其转换为java.util.Set可序列化的.我尝试了以下代码,但得到了
java.io.notserializableexception: scala.collection.convert.wrappers$setWrapper
import scala.collection.JavaConversions._
Class MySerializableClass extends Serializable {
// method to implement the Scala to Java operations on the given RDD
def rddOps(dummyRDD: RDD[(Long, Set[Long])]) = {
val dummyRDDWithJavaSet = dummyRDD.map( {
case(key, value) => (key, scalaToJavaSetConverter(value))
}
// scala Set to Java Set Converters
def scalaToJavaSetConverter(scalaSet: Set[Long]): java.util.Set[Long] = {
val javaSet : java.util.Set[Long] = setAsJavaSet(scalaSet)
javaSet
}
}
Run Code Online (Sandbox Code Playgroud)
我在尝试序列化从scala转换的java地图时看到了线程不可序列化的异常,但是该解决方案不适用于序列化