/**
* 隐式参数
*/
object Context_Implicits {
implicit val default: String = "Java"
}
object Param {
//编译器会检查谁是implicit的变量(全局范围内查找隐式值),如果有,会默认传递过来
def print(content: String) (implicit language: String): Unit = {
println(language + " : " + content)
}
}
object Implicit_Parameters {
def main(args: Array[String]): Unit = {
Param.print("Spark")("Scala")
//引入隐式变量
import Context_Implicits._
Param.print("Hadoop")
}
}
scala进阶18-隐式转换-隐式参数
最新推荐文章于 2016-08-30 00:50:46 发布