尝试了解如何在 scala 中使用类型:
object TypeSample extends App {
type MyParams = Map[Int, String]
def showParams(params: MyParams) = {
params.foreach(x => x match { case (a, b) => println(a + " " + b) })
}
//val params = MyParams( 1 -> "one", 2 -> "two")
val params = Map( 1 -> "one", 2 -> "two")
showParams(params)
}
此行引发编译异常:“无法解析符号'MyParams'”
//val params = MyParams( 1 -> "one", 2 -> "two")
为什么?我不能像这样使用“类型”吗?