0

I'm overloading a function but I came across a problem

fun setNumbers(numbers: Array<Int>) {

}

clashes with

fun setNumbers(vararg numbers : Int) {

}

but none of them can deal with both

setAdapters(Array...)
setAdapters(varargs...)

is there any trick to make both of them not clash or accept both calls?

0

1 Answer 1

2

There isn't a real trick in the sense that you can't avoid the clash (without changing the name of the function), but you can call the vararg function as follows:

setNumbers(*intArrayOf(1, 2, 3))
Sign up to request clarification or add additional context in comments.

1 Comment

Yeah this is the way the docs tell you to use an existing array: kotlinlang.org/docs/reference/…

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.