Can the lambda of kotlin be a variable parameter function?

want to implement a function similar to that in js


require(["a", "b", "c"], function(a, b, c){



})

ask, how is it written as a parameter in a lambda?

Mar.02,2021

cannot be written. Refer to https://stackoverflow.com/que.


unfortunately cannot be implemented. As mentioned in the question and answer of StackOverflow provided by codegoose, kotlin's lambda does not provide support for the vararg modifier for the time being

to implement the function definition you need, here are two similar implementations I know

// 
interface Cry {
    fun crying(vararg x : String)
}

private fun require(vararg config: String, cry: Cry) {
    cry.crying(*config)
}

fun test1() {
    val config = arrayOf("1", "2")
    require(*config, cry = object : Cry {
        override fun crying(vararg x: String) = x.forEach(::println)
    })
}

// arrayOfvarargArray<out String>
private fun require(vararg config: String, block : (Array<out String>) -> Unit) {
    block(config)
    block(arrayOf("1", "2", "3"))
}

fun test2() {
    val config = arrayOf("1", "2")
    require(*config, block = { it.forEach(::println)})
}
MySQL Query : SELECT * FROM `codeshelper`.`v9_news` WHERE status=99 AND catid='6' ORDER BY rand() LIMIT 5
MySQL Error : Disk full (/tmp/#sql-temptable-64f5-1e7d205-930.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
MySQL Errno : 1021
Message : Disk full (/tmp/#sql-temptable-64f5-1e7d205-930.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
Need Help?