class QRcodeAnalyzer(private val resultHandler: (String?) -> Unit) val handler=fun(str:String?){ print(str) } fun main() { var a=QRcodeAnalyzer(handler) }
3.2 参数-简写形式(将fun去掉)
1 2 3 4 5 6 7
class QRcodeAnalyzer(private val resultHandler: (String?) -> Unit) val handler = { str: String? -> print(str) } fun main() { var a=QRcodeAnalyzer(handler) }
3.3 函数形式(handler())
1 2 3 4 5
class QRcodeAnalyzer(private val resultHandler: (String?) -> Unit) fun handler():(str:String?)->Unit= { print(it)} fun main() { var a=QRcodeAnalyzer(handler()) }