Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to make vararg parameter which gets at least one argument?

Tags:

kotlin

I have the following code:

fun qwer(vararg x: String){
}

fun main() {
    qwer()
}

As you can see i can pass 0 strings to qwer function. Is there a way to make qwer function get at least one argument ?

like image 925
VanechikSpace Avatar asked Oct 15 '25 00:10

VanechikSpace


1 Answers

You could do something like this:

fun qwer(first: String, vararg x: String) {

}

So, calling qwer() errors out but qwer("hello") is fine.

like image 88
Dj Sushi Avatar answered Oct 19 '25 00:10

Dj Sushi



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!