I have this map `private val routes = mapOf<Reg...
# getting-started
o
I have this map
private 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
there
y
vararg
is syntatic sugar for Arrays, so use
args: Array<String>
instead like so:
Copy code
private val routes = mapOf<Regex, (args: Array<String>) -> LaunchAction?>(
o
oh..
lol ok TIL
thanks
👍 1
r
As the old adage goes
Don'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>
.
y
I'm assuming that they're already using
vararg
elsewhere and so they expect arrays everywhere