How can I put function references into an array?

I’m trying to put function references into an array and call those functions from elsewhere. I can get this working if I assign lambdas to variables and then put the variables in the array but not when I try function references.
(Code example is cut-n-paste fragments - not actual code)

private typealias ActionHandler = (BState, BEvent, ActionPayload?) -> Unit
private typealias ActionMap = HashMap<BState, HashMap<BEvent, Pair<Array<ActionHandler>, BState?>>>


object MyService {
    private lateinit var actionMap: ActionMap

    init() {
        actionMap[BState.OFF_LINE]?.put(BEvent.ON_LINE, Pair(arrayOf(functionA), BState.ON_LINE)) // <-- OK
        actionMap[BState.OFF_LINE]?.put(BEvent.ON_LINE, Pair(arrayOf(functionB), BState.ON_LINE)) // <-- Fails

    private var functionA: ActionHandler =
        { state: BState, event: BEvent, payload: ActionPayload? ->
            Log.d(TAG, "In functionA")
    private fun functionB(state: BState, event: BEvent, payload: ActionPayload?) : Unit {
        Log.d(TAG, "In functionB")


The line that fails gives a type mismatch error.
Any suggestions would be welcome.


You are storing the result of functionB, which is Unit, instead of a reference to functionB. Try this:

actionMap[BState.OFF_LINE]?.put(BEvent.ON_LINE, Pair(arrayOf(::functionB), BState.ON_LINE))

That’s got it… Many thanks…!!