https://kotlinlang.org logo
Title
s

Saiedmomen

08/27/2019, 5:15 AM
Is there a way to pass function with optional argument like
fun fetchData(page=0) {...}
to a function that expects a function with no argument like?
fun runRequest(block: ()->Unit)
k

kralli

08/27/2019, 6:04 AM
You mean like
runRequest(::fetchData)
?
s

Saiedmomen

08/27/2019, 6:07 AM
yep
I thought there might be sth like
@JvmOverloads
that I've missed
b

Big Chungus

08/27/2019, 7:31 AM
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
fun runRequest(block: (()->Unit) = {})