0
Variadic Parameter vs. Array
What is the purpose of a variadic parameter when we can just use an array instead?
3 odpowiedzi
+ 11
I think using the variadic parameter is easier than using an array.
If you are going to use an array you have to create the array and then pass it to the function.
But with the variadic parameter, you just pass the arguments to the function and the array is created for you.
Edited:
Although variadic parameters are considered sintatic sugar, it does have some limitations:
- You can have only one in a function.
- It must come last.
In situations where you do want to overcome such limitations use arrays.
0
Thanks!