java类型的map转为scala类型map
package com.xxx.spark.flow.util.common; import scala.collection.JavaConverters; import scala.collection.Map$; import java.util.Map; /** * @AUTHOR Guozy * @DESCRIBTION some methods about map * @DATE 2020/12/25-11:40 **/ public class MapUtils { /** * convert java's map to scala's map * * @param map java.util.map * @return map scala.collection.immutable.map */ public static scala.collection.immutable.Map<String, String> javaMapConvertToScalaMap(Map<String, String> map) { scala.collection.mutable.Map<String, String> scalaMap = JavaConverters.mapAsScalaMapConverter(map).asScala(); Object objMap = Map$.MODULE$.<String, String>newBuilder().$plus$plus$eq(scalaMap.toSeq()); Object BuildResObjMap = ((scala.collection.mutable.Builder) objMap).result(); scala.collection.immutable.Map<String, String> targetScalaMap = (scala.collection.immutable.Map) BuildResObjMap; return targetScalaMap; } }