标签:read 定时 div cep main 接收 object 参数 blog
object Helloworld { def oncePerSecond(callback:(Int) => Unit): Unit ={ val a = 111 while (true){ callback(a) Thread sleep 1000 } } def sendinfo(i:Int): Unit ={ println("hello"+i) } def main(args: Array[String]): Unit = { oncePerSecond(sendinfo) } }
其中callback是一个int => Unit的函数名,oncePerSecond接收一个函数作为参数,而不是这个函数的结果,因此该函数sendinfo传入时不需要带参数,如果带参数则编译器会将其理解为这个函数的结果,也就是Unit
标签:read 定时 div cep main 接收 object 参数 blog
原文地址:http://www.cnblogs.com/LazyJoJo/p/7472805.html