class student{ def sayHello(name: => String){ println(s"Hello, $name, welcome $name") } } object FunctionDemo3 { def main(args: Array[String]): Unit = { val s = new student() def getSName(s: String): String = {println("call"); s} //传名参数 s.sayHello("Sky") s.sayHello(getSName("Sky")) } }
Hello, Sky, welcome Sky call call Hello, Sky, welcome Sky