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
转载于:https://www.cnblogs.com/AK47Sonic/p/7072735.html
相关资源:Scala学习笔记(全)