null or empty lambda as default value

后端 未结 2 1455
南笙
南笙 2021-02-05 11:36

which solution is better? use nullable lambda or pass empty lambda as default parameter? would kotlin optimize somehow empty lambda ? or create new instance that do nothing?

2条回答
  •  长情又很酷
    2021-02-05 12:29

    Look the last paremter of the exposed function:

    internal fun showDialog(title: String, message:String?= null, okButtonAction: () -> Unit, koButtonAction:() -> Unit = {}){ //do things.....}
    

提交回复
热议问题