有一個java方法返回一個對象java
public Map<String, String> getFieldTypeMap() { ... }
如今在scala中調用該方法scala
val fieldTypeMap = someObject.getFieldTypeMap() val innerSQL = fieldTypeMap.map { case (key: String, value: String) => key.replace(".", "_")}.toStream.sorted.reduce(_ + "," + _)
報錯:code
Error:(19, 35) value map is not a member of java.util.Map[String,String] val structureSQL = fieldTypeMap.map{ case (key: String, value: String) => key.replace(".", "_")
須要添加:對象
@Deprecated import scala.collection.JavaConversions._
須要添加:get
import scala.collection.JavaConverters.mapAsScalaMapConverter
而後在使用時用toScala:io
val fieldTypeMap = someObject.getFieldTypeMap() val innerSQL = fieldTypeMap.toScala.map { case (key: String, value: String) => key.replace(".", "_")}.toStream.sorted.reduce(_ + "," + _)