Is there a way to pass function with optional argu...
# announcements
s
Is there a way to pass function with optional argument like
Copy code
fun fetchData(page=0) {...}
to a function that expects a function with no argument like?
Copy code
fun runRequest(block: ()->Unit)
k
You mean like
runRequest(::fetchData)
?
s
yep
I thought there might be sth like
@JvmOverloads
that I've missed
b
fun runRequest(block: (()->Unit)? = null)
Function type behaves just like any other type and thus can be nullable. You can also pass in the default implementation such as
Copy code
fun runRequest(block: (()->Unit) = {})