Kotlin高阶函数

高阶函数,就是函数作为参数传递

fun main(args: Array<String>) {

   args.forEach (::println)

}

深入去理解

forEach参数是(T) -> Unit,返回是Unit
fun main(args: Array<String>) {

    var hTestClass = HTestClass::hf
//    hTestClass.invoke(hf)

    //得到Hello实列
    val hello = Hello::world
    val hello2 = Hello::world2
    hello.invoke(Hello());
    hello2.invoke(Hello());
//    hello.world();
}



class HTestClass{

    fun hf(){
        println("this is H Fun")
    }


}

class Hello{
    fun world(){

        println("this is H Fun")
    }

    fun world2(){

        println("this is H Fun2")
    }
}

猜你喜欢

转载自blog.csdn.net/renfujiang/article/details/89317514