Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the meaning Params... ? in android

Tags:

android

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.

like image 983
whale_steward Avatar asked Dec 07 '22 19:12

whale_steward


2 Answers

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.

like image 78
Nayan Srivastava Avatar answered Dec 10 '22 12:12

Nayan Srivastava


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.

like image 34
Robert Avatar answered Dec 10 '22 11:12

Robert