Here's my function:
fun setSingleChoiceItems(items: Array<CharSequence>?, checkedItem: Int,
listener: DialogInterface.OnClickListener?) {
// ...
}
I tried to invoke it with String array (converted from List):
val str = listOf("1", "2", "3")
dialog.setSingleChoiceItems(str.toTypedArray(), currentChoice, null)
My IDE gives no errors or warnings but I encountered a compilation error: None of the following functions can be called with the arguments supplied.
I tried to add an convenience function to accept String array:
fun setSingleChoiceItems(items: Array<String>?, checkedItem: Int,
listener: DialogInterface.OnClickListener?) {
// Here's a warning: No cast needed
val cs = items?.map { it as CharSequence }?.toTypedArray()
setSingleChoiceItems(cs,checkedItem,listener)
}
Now it can compile successfully but I encountered an IDE error: Overload resolution ambiguity. All these functions match.
It seems that the only correct way is to explicitly convert when calling -- without convenience method. Obviously this is very troublesome.
So what is the best way to solve this issue?