Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there any way to get list of arguments in Kotlin for function

Tags:

kotlin

Is there a way to get list of arguments for a function in Kotlin like Javascript has arguments.

thanks

like image 747
maheshgupta024 Avatar asked Dec 30 '25 18:12

maheshgupta024


1 Answers

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")
like image 95
Joffrey Avatar answered Jan 01 '26 14:01

Joffrey



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!