Is there a way to get list of arguments for a function in Kotlin like Javascript has arguments.
thanks
There is no direct Kotlin equivalent to JavaScript's arguments implicit object.
However, if you really want to access arguments as a list, you can either use an actual List like this:
fun myFunc(args: List<String>) {
// do something with the list "args"
}
// call it this way:
myFunc(listOf("a", "b", "c"))
Or you can use varargs, which create an array implicitly for you, like this:
fun myFun(vararg args: String) {
// use "args" as an Array<out String>
}
// call it this way:
myFunc("a", "b", "c")
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With