oday
03/15/2022, 1:05 PMprivate val routes = mapOf<Regex, (vararg args: String) -> LaunchAction?>(
I would like to accept a variable number of arguments in that anonymous function defined as the map’s value, how can I do that? I’m not allowed to set a modifier like vararg
thereYoussef Shoaib [MOD]
03/15/2022, 1:10 PMvararg
is syntatic sugar for Arrays, so use args: Array<String>
instead like so:
private val routes = mapOf<Regex, (args: Array<String>) -> LaunchAction?>(
oday
03/15/2022, 1:10 PModay
03/15/2022, 1:11 PModay
03/15/2022, 1:11 PMRuckus
03/15/2022, 9:14 PMDon't use an array unless you need an array. If you don't know if you need an array, you don't need an array.That is to say, I'd probably just stick with
List<String>
.Youssef Shoaib [MOD]
03/15/2022, 9:41 PMvararg
elsewhere and so they expect arrays everywhere