Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What are these three dots in parameter types [duplicate]

Tags:

java

Possible Duplicate:
What is the ellipsis for in this method signature?

For example: protected void onProgressUpdate(Context... values)

like image 402
Eugene Avatar asked Mar 07 '11 19:03

Eugene


People also ask

What do the 3 dots in JavaScript mean?

(three dots in JavaScript) is called the Spread Syntax or Spread Operator. This allows an iterable such as an array expression or string to be expanded or an object expression to be expanded wherever placed.

What does 3 dots mean in react?

The three dots (…) notation referred to as the Spread syntax has been part of React for a long time when it could be used via transpilation, although, it has been made a part of JavaScript as part of the ES2015 syntax.

What do 3 dots mean in Typescript?

The three dots are known as the spread operator from Typescript (also from ES7). The spread operator return all elements of an array. Like you would write each element separately: let myArr = [1, 2, 3]; return [1, 2, 3]; //is the same as: return [...myArr];

What do three dots above and below code mean?

When we see three dots (…) in the code, it's either rest parameters or the spread operator. There's an easy way to distinguish between them: When three dots (…) is at the end of function parameters, it's "rest parameters" and gathers the rest of the list of arguments into an array.


3 Answers

One word: varargs.

The three periods after the final parameter's type indicate that the final argument may be passed as an array or as a sequence of arguments. Varargs can be used only in the final argument position.

like image 50
Matt Ball Avatar answered Sep 22 '22 16:09

Matt Ball


They're called varargs, and were introduced in Java 5. Read http://download.oracle.com/javase/1.5.0/docs/guide/language/varargs.html for more information.

In short, it allows passing an array to a method without having to create one, as if the method took a variable number of arguments. In your example, the following four calls would be valid :

onProgressUpdate();
onProgressUpdate(context1);
onProgressUpdate(context1, context2, context3);
onProgressUpdate(new Context[] {context1, context2});
like image 27
JB Nizet Avatar answered Sep 23 '22 16:09

JB Nizet


Its the varargs introduced in java 5. more info at Varargs

like image 22
Manoj Avatar answered Sep 23 '22 16:09

Manoj