/** * 隐式转换函数——隐式参数 */ class SingPen { def write(content: String): Unit = { println(content) } } object ImplicitDemo3 { // def exam(name: String, pen: SingPen): Unit = { //被implicit修饰的参数就是隐式参数 def exam(name: String)(implicit pen: SingPen): Unit = { pen.write(name) } def main(args: Array[String]): Unit = { implicit val pen = new SingPen exam("李四") exam("张三") // exam("李四", pen) // exam("王五", pen) } }
Scala隐式转换之隐式参数
最新推荐文章于 2018-12-24 12:58:37 发布