Nezteb
04/23/2019, 9:37 PM::funcName
funcName
funcName()
?
The last one I believe is a function invocation, ie () -> Unit
, but the first two confuse me.Alowaniak
04/23/2019, 9:52 PMCzar
04/23/2019, 10:06 PMstreetsofboston
04/23/2019, 10:49 PMfun funcName() : Unit { ... }
::funcName
is a function reference and can be cast easily to a lambda:
val funcRef : KFunction<Unit> = ::funcName // OK
val funcLambda : () -> Unit = ::funcName // OK
val givesCompileError: () -> Unit = funcRef // compiler error
funcName
is not possible in Kotlin. This will give a syntax error. This syntax denootes either a value/variable, parameter, field, etc.
funcName()
is calling the function, executing it, returning its return value.
// These do all the exact same
funcName()
funcRef.call()
funcLambda()
Nezteb
04/23/2019, 11:21 PM