I'm stil new with android dev, so today I stumble upon this code in android docs
Result doInBackground (Params... params)
What is the meaning of Params...
? is it the same as Params
? but when using Params
(without ...), it throw an error not override abstract.
This confuse me.
It is a Java concept know as var args
. It is sugar syntax to pass array of certain type in as method argument.
So when you say
Result doInBackground (Integer... args)
{
Integer [] vals=args;
}
and you can access values from that array.
As far as AsyncTask's methods are concerned, you can change argument type from Params
to the type you need. Params
is just a template which you need to change during implementation.
This in Java is called varargs
and is an array of params but with different syntax. you can take a look the doc about this by clicking here
Also this question has an answer for you.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With