Invoking nullable function variable


#1

I had a function variable defined as follows (using Delegates) and it works:

 
var fun: () -> Unit by Delegates.notNull()

... but I would like to make it nullable and invoke it only when it is not null as below:

 
var fun2: (() -> Unit)? = null
 

... however, when I call fun2() it's marked as "UNSAFE_CALL" and won't compile, I don't know where to put '?" to invoke it correctly. Please help.

EDIT:

Found solution:

 
fun2?.invoke()