我有一个 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
}
}
我在尝试序列化从 scala 转换为答案的 java map 时看到了线程 notserializable 异常,但该解决方案不适用于序列化