Hello you guys,
So I have a question,Why we can not use
arrayListOf
as parameter , only ArrayList can accept to use as parameter
Copy code
1. class CategoriesViewHolder(context: Context,categories:ArrayList<Category>){}
2. val categories = arrayListOf<String>()
Thanks
g
gergo
09/10/2019, 8:58 AM
I might not get what you mean, but ArrayList is a type while arrayListOf is a function to create an ArrayList. You can use arrayListOf to have a default parameter for your method if that's what you are trying to achieve.
fun foo(bar: ArrayList<Int> = arrayListOf()){}
s
Sam
09/10/2019, 8:59 AM
Screen Shot 2019-09-10 at 3.59.05 PM.png
g
gergo
09/10/2019, 8:59 AM
still, arrayListOf is a function to create an ArrayList, it's not a type
gergo
09/10/2019, 9:00 AM
if you want to add any number of elements to the method via commas, then you may want to use vararg