Eganathan R
01/04/2025, 4:54 AMKlitos Kyriacou
01/06/2025, 9:28 AM*list.toTypedArray()
as a vararg causes the list to be copied into a newly allocated array. This can waste CPU time and memory resources if you are doing this in a tight loop in an environment where resources are very limited and/or where performance is extremely important. I prefer having an overloaded function instead:
fun doSomething(vararg items: Item) = doSomething(items.asList())
fun doSomething(items: List<Item>) { ... }
Also, I don't see any problem with passing an empty argument list. If doSomething
can take a vararg of any size, where is this "danger" that you talk of? If you pass nothing, doSomething
behaves correctly by doing nothing.Eganathan R
01/07/2025, 2:29 AM