https://kotlinlang.org logo
#getting-started
Title
# getting-started
o

oday

03/15/2022, 1:05 PM
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

Youssef Shoaib [MOD]

03/15/2022, 1:10 PM
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

oday

03/15/2022, 1:10 PM
oh..
lol ok TIL
thanks
👍 1
r

Ruckus

03/15/2022, 9:14 PM
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

Youssef Shoaib [MOD]

03/15/2022, 9:41 PM
I'm assuming that they're already using
vararg
elsewhere and so they expect arrays everywhere
3 Views