java - what is Object... in method arguments and how can I use it? -


this question has answer here:

i want use method in java. prototype defined below:

 public void fragmentrequestaction(fragment fragment, int requestid, object... objects) 

i not know object... how can pass such items method , how can use them?

the object... takes non-primitive type , @ number. in java called variable length argument.

it means may call fragmentrequestaction() method -

fragmentrequestaction(fragment, 345); //no object here fragmentrequestaction(fragment, 345, someobj); fragmentrequestaction(fragment, 345, someobj1, someobj2); fragmentrequestaction(fragment, 345, someobj1, someobj2, someobj3);   

variable length argument intruded java 5. there rules remember while constructing function variable length arguments. see code snippet -

public void meth ( int... a) // valid public void meth (double a, int... b) // valid public void meth ( int... a, int b) // invalid- ellipsis may used towards end public void meth ( int... a, double... b) // invalid - more 1 variable length parameter list may not used public void meth ( student... a) // valid - reference types allowed public void meth( int[]... a) // valid - reference types allowed  

visit link more details.


Comments

Popular posts from this blog

python - TypeError: start must be a integer -

c# - DevExpress RepositoryItemComboBox BackColor property ignored -

django - Creating multiple model instances in DRF3 -