java与scala一起使用:
java的List与scala的buffer转换:
前提是转换的java类型和scala类型必须也要import,再去import scala.collection.JavaConversions._ ,并且相互转换的集合都必须要有明确的类型
?
import scala.collection.javaConversions.bufferAsJavaList
val javaList = new ProcessBuilder(ArrayBuffer(1)) //它会返回一个javaList的对象
import scala.collection.mutable.ArrayBuffer
val buff:Buffer[Int] = new java.util.ArrayList[Int]() //它会自动转变成Buffer
import scala.collection.javaConversions.mapAsScalaMap
val scalaMap = new java.util.TreeMap[String,Int] //它会自动转变成scala中的map
import scala.collection.JavaConversions.propertiesAsScalaMap
val scalaMap = System.getProperties() //它会自动转变成scala中的map
import scala.collection.javaConversions.mapAsJavaMap
import java.awt.font.TextAttribute._ //引入下面的映射会用到的键
val font = new java.awt.Font(Map("1" -> 1,"2" -> 2)) //该方法预期一个Java映射